Skip to content

Commit 51c3d59

Browse files
committed
Punycode identifiers that start with a numeral.
1 parent a2a335b commit 51c3d59

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

include/swift/Demangling/ManglingUtils.h

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,16 @@ inline bool isWordEnd(char ch, char prevCh) {
5858
return false;
5959
}
6060

61+
/// Returns true if \p ch is a valid character which may appear at the start
62+
/// of a symbol mangling.
63+
inline bool isValidSymbolStart(char ch) {
64+
return isLetter(ch) || ch == '_' || ch == '$';
65+
}
66+
6167
/// Returns true if \p ch is a valid character which may appear in a symbol
62-
/// mangling.
68+
/// mangling anywhere other than the first character.
6369
inline bool isValidSymbolChar(char ch) {
64-
return isLetter(ch) || isDigit(ch) || ch == '_' || ch == '$';
70+
return isValidSymbolStart(ch) || isDigit(ch);
6571
}
6672

6773
/// Returns true if \p str contains any character which may not appear in a

lib/Demangling/ManglingUtils.cpp

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,16 @@ bool Mangle::isNonAscii(StringRef str) {
2626
}
2727

2828
bool Mangle::needsPunycodeEncoding(StringRef str) {
29-
for (unsigned char c : str) {
30-
if (!isValidSymbolChar(c))
29+
if (str.empty()) {
30+
return false;
31+
}
32+
if (!isValidSymbolStart(str.front())) {
33+
return true;
34+
}
35+
for (unsigned char c : str.substr(1)) {
36+
if (!isValidSymbolChar(c)) {
3137
return true;
38+
}
3239
}
3340
return false;
3441
}

test/Demangle/Inputs/manglings.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,4 +481,5 @@ _$s4test3fooyyF ---> test.foo() -> ()
481481
_$s4test0014foospace_ntJBbyyF ---> test.foo space() -> ()
482482
_$s4test0012_3times_bpJCayyF ---> test.3 times() -> ()
483483
_$s4test0011test_DkJtFbyyF ---> test.test +() -> ()
484-
_$s4test0016pathfoo_yuEHaaCiyyF ---> test
484+
_$s4test0016pathfoo_yuEHaaCiyyF ---> test.path://foo() -> ()
485+
_$s4test10FontWeightV004_100_yyF ---> test.FontWeight.100() -> ()

0 commit comments

Comments
 (0)