Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions javascript/ql/src/semmle/javascript/Regexp.qll
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,19 @@ class RegExpQuantifier extends RegExpTerm, @regexp_quantifier {
predicate isGreedy() { is_greedy(this) }
}

/**
* A regular expression term that permits unlimited repetitions.
*/
class InfiniteRepetitionQuantifier extends RegExpQuantifier {
InfiniteRepetitionQuantifier() {
this instanceof RegExpPlus
or
this instanceof RegExpStar
or
this instanceof RegExpRange and not exists(this.(RegExpRange).getUpperBound())
}
}

/**
* An escaped regular expression term, that is, a regular expression
* term starting with a backslash.
Expand Down Expand Up @@ -1065,6 +1078,12 @@ module RegExp {
not cls.isInverted() and
cls.getAChild().(RegExpCharacterClassEscape).getValue().isUppercase()
)
or
// an unlimited number of wildcards, is also a wildcard.
exists(InfiniteRepetitionQuantifier q |
term = q and
isWildcardLike(q.getAChild())
)
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ module Shared {
class MetacharEscapeSanitizer extends Sanitizer, StringReplaceCall {
MetacharEscapeSanitizer() {
isGlobal() and
RegExp::alwaysMatchesMetaCharacter(getRegExp().getRoot(), ["<", "'", "\""])
(
RegExp::alwaysMatchesMetaCharacter(getRegExp().getRoot(), ["<", "'", "\""])
or
// or it's like a wild-card.
RegExp::isWildcardLike(getRegExp().getRoot())
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,6 @@ private predicate isReDoSCandidate(State state, string pump) {
)
}

/**
* A regular expression term that permits unlimited repetitions.
*/
class InfiniteRepetitionQuantifier extends RegExpQuantifier {
InfiniteRepetitionQuantifier() {
this instanceof RegExpPlus
or
this instanceof RegExpStar
or
this instanceof RegExpRange and not exists(this.(RegExpRange).getUpperBound())
}
}

/**
* Gets the char after `c` (from a simplified ASCII table).
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,8 @@

$("#id").html(anser.ansiToHtml(text)); // NOT OK
$("#id").html(new anser().process(text)); // NOT OK

$("section h1").each(function(){
$("nav ul").append("<a href='#" + $(this).text().toLowerCase().replace(/ /g, '-').replace(/[^\w-]+/g,'') + "'>Section</a>"); // OK
});
})();