Skip to content

Commit 5c76806

Browse files
committed
Throw error on invalid UTF-8 sequences in parser
Enhanced and sanitized error message for consumer
1 parent 26df96f commit 5c76806

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/parser.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,15 @@ namespace Sass {
9999
// consume unicode BOM
100100
read_bom();
101101

102+
// scan the input to find invalid utf8 sequences
103+
const char* it = utf8::find_invalid(position, end);
104+
105+
// report invalid utf8
106+
if (it != end) {
107+
pstate += Offset::init(position, it);
108+
throw Exception::InvalidSass(pstate, "Invalid UTF-8 sequence");
109+
}
110+
102111
// create a block AST node to hold children
103112
Block_Obj root = SASS_MEMORY_NEW(Block, pstate, 0, true);
104113

0 commit comments

Comments
 (0)