Skip to content

Commit 4ccdb25

Browse files
committed
Improve escaped sequence parsing
1 parent fa02bad commit 4ccdb25

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

src/prelexer.cpp

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,15 @@ namespace Sass {
7070
{
7171
return sequence<
7272
exactly<'\\'>,
73-
any_char
73+
alternatives <
74+
minmax_range<
75+
3, 3, xdigit
76+
>,
77+
any_char
78+
>,
79+
optional <
80+
exactly <' '>
81+
>
7482
>(src);
7583
}
7684

@@ -960,5 +968,19 @@ namespace Sass {
960968
return got ? pos : 0;
961969
}
962970

971+
template <size_t min, size_t max, prelexer mx>
972+
const char* minmax_range(const char* src)
973+
{
974+
size_t got = 0;
975+
const char* pos = src;
976+
while (got < max) {
977+
if (!mx(pos)) break;
978+
++ pos; ++ got;
979+
}
980+
if (got < min) return 0;
981+
if (got > min) return 0;
982+
return pos;
983+
}
984+
963985
}
964986
}

src/prelexer.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,9 @@ namespace Sass {
393393
template <size_t size, prelexer mx, prelexer pad>
394394
const char* padded_token(const char* src);
395395

396+
template <size_t min, size_t max, prelexer mx>
397+
const char* minmax_range(const char* src);
398+
396399
}
397400
}
398401

src/util.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,8 @@ namespace Sass {
363363
// ToDo: Maybe we could do this without creating a substring
364364
uint32_t cp = strtol(s.substr (i + 1, len - 1).c_str(), nullptr, 16);
365365

366+
if (s[i + len] == ' ') ++ len;
367+
366368
// assert invalid code points
367369
if (cp == 0) cp = 0xFFFD;
368370
// replace bell character

0 commit comments

Comments
 (0)