Skip to content

Commit b8a38f8

Browse files
Reject empty quoted identifiers in parser (#8357)
Part of #8261. `""` previously parsed successfully as a name which doesn't match the spec. Change the code to fail to parse this case. Fixes id.wast spec test.
1 parent 3d6dfef commit b8a38f8

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

scripts/test/shared.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,6 @@ def get_tests(test_dir, extensions=[], recursive=False):
422422
'linking.wast', # Missing function type validation on instantiation
423423
'proposals/threads/memory.wast', # Missing memory type validation on instantiation
424424
'annotations.wast', # String annotations IDs should be allowed
425-
'id.wast', # Empty IDs should be disallowed
426425
'instance.wast', # Requires support for table default elements
427426
'table64.wast', # Requires validations for table size
428427
'tag.wast', # Non-empty tag results allowed by stack switching

src/parser/lexer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -866,10 +866,17 @@ std::optional<LexIdResult> ident(std::string_view in) {
866866
if (!ctx.takePrefix("$"sv)) {
867867
return {};
868868
}
869+
// Quoted identifier e.g. $"foo"
869870
if (auto s = str(ctx.next())) {
870871
if (!String::isUTF8(s->getStr())) {
871872
return {};
872873
}
874+
875+
// empty names, including $"" are not allowed.
876+
if (s->span == "\"\"") {
877+
return {};
878+
}
879+
873880
ctx.isStr = true;
874881
ctx.str = s->str;
875882
ctx.take(*s);

test/gtest/wat-lexer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -888,7 +888,7 @@ TEST(LexerTest, LexIdent) {
888888
EXPECT_FALSE(Lexer("$"sv).takeID());
889889

890890
// String IDs
891-
EXPECT_EQ(Lexer("$\"\""sv).takeID(), wasm::Name(""sv));
891+
EXPECT_EQ(Lexer("$\"\""sv).takeID(), std::nullopt);
892892
EXPECT_EQ(Lexer("$\"hello\""sv).takeID(), wasm::Name("hello"sv));
893893
// _$_£_€_𐍈_
894894
EXPECT_EQ(Lexer("$\"_\\u{24}_\\u{00a3}_\\u{20AC}_\\u{10348}_\""sv).takeID(),

test/lit/basic/imported-params.wast

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
(module
88
(import "" "" (func (param i32 i64) (param $x i32) (param $y i64) (param f32 f64)))
99
(import "" "" (func (param $x i32) (param f32 f64) (param $y i64)))
10-
(import "" "" (func (param $"" i32)))
10+
(import "" "" (func (param $"\tfoo" i32)))
1111
)
1212
;; CHECK: (type $0 (func (param i32 i64 i32 i64 f32 f64)))
1313

@@ -19,4 +19,4 @@
1919

2020
;; CHECK: (import "" "" (func $fimport$1 (param $x i32) (param f32 f64) (param $y i64)))
2121

22-
;; CHECK: (import "" "" (func $fimport$2 (param $"" i32)))
22+
;; CHECK: (import "" "" (func $fimport$2 (param $"\tfoo" i32)))

0 commit comments

Comments
 (0)