Skip to content

Commit

Permalink
Fix url parsing with trailing spaces in url
Browse files Browse the repository at this point in the history
Re-factoring in lexer to make args more consistent.
Added loosely match that can be preceded by spaces.
  • Loading branch information
mgreter committed Apr 6, 2015
1 parent f82a41b commit 51b0bf0
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 12 deletions.
2 changes: 1 addition & 1 deletion constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ namespace Sass {
extern const char arglist_name[] = "arglist";

// constants for uri parsing (RFC 3986 Appendix A.)
extern const char uri_chars[] = ":/?!$%&#@[]{}'\"*+-._=";
extern const char uri_chars[] = ":;/?!$%&#@[]{}'\"*+-.,_=";

// some specific constant character classes
// they must be static to be useable by lexer
Expand Down
35 changes: 25 additions & 10 deletions lexer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,19 +77,19 @@ namespace Sass {

// Match a single character literal.
// Regex equivalent: /(?:literal)/
template <char pre>
template <char chr>
const char* exactly(const char* src) {
return *src == pre ? src + 1 : 0;
return *src == chr ? src + 1 : 0;
}

// Match a string constant.
// Regex equivalent: /[axy]/
template <const char* prefix>
template <const char* str>
const char* exactly(const char* src) {
if (prefix == 0) return 0;
const char* pre = prefix;
if (str == 0) return 0;
const char* pre = str;
if (src == 0) return 0;
// there is a small chance that the search prefix
// there is a small chance that the search string
// is longer than the rest of the string to look at
while (*pre && *src == *pre) {
++src, ++pre;
Expand Down Expand Up @@ -117,9 +117,9 @@ namespace Sass {

// Match all except the supplied one.
// Regex equivalent: /[^x]/
template <const char c>
template <const char chr>
const char* any_char_but(const char* src) {
return (*src && *src != c) ? src + 1 : 0;
return (*src && *src != chr) ? src + 1 : 0;
}

// Succeeds if the matcher fails.
Expand Down Expand Up @@ -210,14 +210,29 @@ namespace Sass {

// Match with word boundary rule.
// Regex equivalent: /(?:$mx)\b/
template <const char* mx>
template <const char* str>
const char* word(const char* src) {
return sequence <
exactly < mx >,
exactly < str >,
word_boundary
>(src);
}

template <char chr>
const char* loosely(const char* src) {
return sequence <
optional_spaces,
exactly < chr >
>(src);
}
template <const char* str>
const char* loosely(const char* src) {
return sequence <
optional_spaces,
exactly < str >
>(src);
}

}
}

Expand Down
2 changes: 1 addition & 1 deletion parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ namespace Sass {

Argument* arg;
// some urls can look like line comments (parse literally - chunk would not work)
if (has_url && lex< sequence < uri_value, lookahead < exactly<')'> > > >(false)) {
if (has_url && lex< sequence < uri_value, lookahead < loosely<')'> > > >(false)) {
String* the_url = parse_interpolated_chunk(lexed);
arg = new (ctx.mem) Argument(the_url->pstate(), the_url);
}
Expand Down

0 comments on commit 51b0bf0

Please sign in to comment.