Skip to content

Commit 19bd45e

Browse files
authored
Error for Unicode ranges that have too many ?s after digits (#1373)
Closes #1280
1 parent 6298812 commit 19bd45e

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## 1.35.2
22

3+
* **Potentially breaking bug fix**: Properly throw an error for Unicode ranges
4+
that have too many `?`s after hexadecimal digits, such as `U+12345??`.
5+
36
* **Potentially breaking bug fix:** Fixed a bug where certain local variable
47
declarations nested within multiple `@if` statements would incorrectly
58
override a global variable. It's unlikely that any real stylesheets were

lib/src/parse/stylesheet.dart

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2493,27 +2493,38 @@ abstract class StylesheetParser extends Parser {
24932493
expectIdentChar($u);
24942494
scanner.expectChar($plus);
24952495

2496-
var i = 0;
2497-
for (; i < 6; i++) {
2498-
if (!scanCharIf((char) => char != null && isHex(char))) break;
2496+
var firstRangeLength = 0;
2497+
while (scanCharIf((char) => char != null && isHex(char))) {
2498+
firstRangeLength++;
24992499
}
25002500

2501-
if (scanner.scanChar($question)) {
2502-
i++;
2503-
for (; i < 6; i++) {
2504-
if (!scanner.scanChar($question)) break;
2505-
}
2501+
var hasQuestionMark = false;
2502+
while (scanner.scanChar($question)) {
2503+
hasQuestionMark = true;
2504+
firstRangeLength++;
2505+
}
2506+
2507+
if (firstRangeLength == 0) {
2508+
scanner.error('Expected hex digit or "?".');
2509+
} else if (firstRangeLength > 6) {
2510+
error("Expected at most 6 digits.", scanner.spanFrom(start));
2511+
} else if (hasQuestionMark) {
25062512
return StringExpression.plain(
25072513
scanner.substring(start.position), scanner.spanFrom(start));
25082514
}
2509-
if (i == 0) scanner.error('Expected hex digit or "?".');
25102515

25112516
if (scanner.scanChar($minus)) {
2512-
var j = 0;
2513-
for (; j < 6; j++) {
2514-
if (!scanCharIf((char) => char != null && isHex(char))) break;
2517+
var secondRangeStart = scanner.state;
2518+
var secondRangeLength = 0;
2519+
while (scanCharIf((char) => char != null && isHex(char))) {
2520+
secondRangeLength++;
2521+
}
2522+
2523+
if (secondRangeLength == 0) {
2524+
scanner.error("Expected hex digit.");
2525+
} else if (secondRangeLength > 6) {
2526+
error("Expected at most 6 digits.", scanner.spanFrom(secondRangeStart));
25152527
}
2516-
if (j == 0) scanner.error("Expected hex digit.");
25172528
}
25182529

25192530
if (_lookingAtInterpolatedIdentifierBody()) {

0 commit comments

Comments
 (0)