Skip to content

Commit b877c35

Browse files
committed
[YAMLIO] Correctly diagnose empty alias/anchor
The `Range` of an alias/anchor token includes the leading `&` or `*`, but it is skipped while parsing the name. The check for an empty name fails to account for the skipped leading character and so the error is never hit. Fix the off-by-one and add a couple regression tests. Reviewed By: dexonsmith Differential Revision: https://reviews.llvm.org/D91462
1 parent c37cc6b commit b877c35

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

llvm/lib/Support/YAMLParser.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,7 @@ bool Scanner::scanAliasOrAnchor(bool IsAlias) {
14231423
++Column;
14241424
}
14251425

1426-
if (Start == Current) {
1426+
if (Start + 1 == Current) {
14271427
setError("Got empty alias or anchor", Start);
14281428
return false;
14291429
}

llvm/unittests/Support/YAMLIOTest.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3101,3 +3101,15 @@ TEST(YAMLIO, TestUnknownDirective) {
31013101
EXPECT_FALSE(yin2.setCurrentDocument());
31023102
EXPECT_TRUE(yin2.error());
31033103
}
3104+
3105+
TEST(YAMLIO, TestEmptyAlias) {
3106+
Input yin("&");
3107+
EXPECT_FALSE(yin.setCurrentDocument());
3108+
EXPECT_TRUE(yin.error());
3109+
}
3110+
3111+
TEST(YAMLIO, TestEmptyAnchor) {
3112+
Input yin("*");
3113+
EXPECT_FALSE(yin.setCurrentDocument());
3114+
EXPECT_TRUE(yin.error());
3115+
}

0 commit comments

Comments
 (0)