Skip to content

Commit

Permalink
Improve escaped sequence parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
mgreter committed Aug 22, 2015
1 parent fa02bad commit 4ccdb25
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
24 changes: 23 additions & 1 deletion src/prelexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,15 @@ namespace Sass {
{
return sequence<
exactly<'\\'>,
any_char
alternatives <
minmax_range<
3, 3, xdigit
>,
any_char
>,
optional <
exactly <' '>
>
>(src);
}

Expand Down Expand Up @@ -960,5 +968,19 @@ namespace Sass {
return got ? pos : 0;
}

template <size_t min, size_t max, prelexer mx>
const char* minmax_range(const char* src)
{
size_t got = 0;
const char* pos = src;
while (got < max) {
if (!mx(pos)) break;
++ pos; ++ got;
}
if (got < min) return 0;
if (got > min) return 0;
return pos;
}

}
}
3 changes: 3 additions & 0 deletions src/prelexer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,9 @@ namespace Sass {
template <size_t size, prelexer mx, prelexer pad>
const char* padded_token(const char* src);

template <size_t min, size_t max, prelexer mx>
const char* minmax_range(const char* src);

}
}

Expand Down
2 changes: 2 additions & 0 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -363,6 +363,8 @@ namespace Sass {
// ToDo: Maybe we could do this without creating a substring
uint32_t cp = strtol(s.substr (i + 1, len - 1).c_str(), nullptr, 16);

if (s[i + len] == ' ') ++ len;

// assert invalid code points
if (cp == 0) cp = 0xFFFD;
// replace bell character
Expand Down

0 comments on commit 4ccdb25

Please sign in to comment.