This repository was archived by the owner on Oct 12, 2022. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -97,12 +97,23 @@ private string miniFormat(V)(const scope ref V v)
97
97
{
98
98
static if (is (V == char ))
99
99
{
100
- return [' \' ' , v, ' \' ' ];
100
+ // Avoid invalid code points
101
+ if (v < 0x7F )
102
+ return [' \' ' , v, ' \' ' ];
103
+
104
+ uint tmp = v;
105
+ return " cast(char) " ~ miniFormat(tmp);
101
106
}
102
107
else static if (is (V == wchar ) || is (V == dchar ))
103
108
{
104
- import core.internal.utf : toUTF8;
105
- return toUTF8 ([' \' ' , v, ' \' ' ]);
109
+ import core.internal.utf : isValidDchar, toUTF8;
110
+
111
+ // Avoid invalid code points
112
+ if (isValidDchar(v))
113
+ return toUTF8 ([' \' ' , v, ' \' ' ]);
114
+
115
+ uint tmp = v;
116
+ return " cast(" ~ V.stringof ~ " ) " ~ miniFormat(tmp);
106
117
}
107
118
else
108
119
{
Original file line number Diff line number Diff line change @@ -67,6 +67,11 @@ void testStrings()
67
67
test(' A' , ' B' , " 'A' != 'B'" );
68
68
test(wchar (' ❤' ), wchar (' ∑' ), " '❤' != '∑'" );
69
69
test(dchar (' ❤' ), dchar (' ∑' ), " '❤' != '∑'" );
70
+
71
+ // Detect invalid code points
72
+ test(char (255 ), ' B' , " cast(char) 255 != 'B'" );
73
+ test(wchar (0xD888 ), wchar (' ∑' ), " cast(wchar) 55432 != '∑'" );
74
+ test(dchar (0xDDDD ), dchar (' ∑' ), " cast(dchar) 56797 != '∑'" );
70
75
}
71
76
72
77
void testToString ()()
You can’t perform that action at this time.
0 commit comments