Commit c079845
committed
refactor(text,text-json,globalization,core): one UTF-8 scalar decode, in one place (#2354)
#2014 found five copies of this runtime's UTF-8 scalar decode, factored the rule
into System/detail/Utf8Scalar.hpp and moved the two .cpp ones. #2354 was the
follow-up for the three header-inline copies it left alone as "entangled with
those types' own decode loops".
THE TICKET NAMED THREE COPIES AND THERE WERE SIX. Measured by grepping for the
continuation-byte test across every module:
UnicodeEncoding.hpp named moved
UTF32Encoding.hpp named moved
Rune.hpp named moved
Utf8JsonWriter.cpp NOT moved -- byte-for-byte identical to the shared one
IdnMapping.cpp NOT moved
UTF8Encoding.cpp NOT moved -- see below
Zero copies remain. That the count could be wrong by a factor of two is the
finding, not a footnote: a rule duplicated often enough that nobody can enumerate
its copies is exactly the shape that produced the defects #2014 and the IdnMapping
repair were written to fix -- "\xC2\x41" decoding to a garbage code point,
"\xC0\x80" decoding straight through to real U+0000.
THE COPIES WERE NOT GRATUITOUS, AND THAT IS PRESERVED RATHER THAN COLLAPSED.
Three doors want three different things, and they differ on exactly one input
class: a STRUCTURALLY VALID encoding of a value that is not a Unicode scalar -- a
surrogate, or a value above U+10FFFF.
Rune::TryGetRuneAt reports failure, consuming the SEQUENCE'S OWN LENGTH, so a
caller can step over the whole thing
any Encoding substitutes U+FFFD over ONE BYTE, so it emits one
replacement per byte, which is .NET's replacement
DecoderFallback
IdnMapping throws, because a domain name comes from untrusted input
So the shared header has TWO entry points, not one. TryDecodeUtf8Scalar reports;
DecodeUtf8Scalar is five lines on top of it and substitutes. Collapsing the two
would have been a silent behaviour change in whichever door lost.
THE COPY #2014 COULD NOT MOVE. UTF8Encoding.cpp's wellFormedUtf8Length reads a
(pointer, end) range rather than a std::string and returns a validity LENGTH
rather than a code point, because its well-formed bytes pass through unchanged and
there is no re-encoding step to fold a substitution into. That was a real
obstacle. The answer is that the range is now a PARAMETER of the shared decode.
`size` is an exclusive bound, so a caller decoding a sub-range gets a truncated
sequence reported as ill-formed instead of read past.
IdnMapping's two hand-spelled extra rejections are subsumed exactly: a 2-byte lead
below 0xC2 is an overlong encoding, and a 4-byte lead above 0xF4 encodes a value
above U+10FFFF.
THE TEST THAT DID NOT EXIST. Rune::TryGetRuneAt had NO test anywhere in the
repository, and the mutation that collapses its length onto the Encoding contract
passed all 17,296 tests then present. Five cases added:
Text 311 -> 314 the Rune/Encoding contrast, per-branch overlong rows
Globalization 681 -> 683 the throwing contract, and the two subsumed rules
Two files rather than one because modules/text does not depend on Globalization,
and a refactor is not a reason to add a public component edge. The module graph is
unchanged at 41 modules / 92 edges, verified.
Five mutations, all caught -- but TWO of them only after a new assertion, and both
are recorded rather than quietly fixed, because they measure how much of this rule
was untested while it was duplicated six ways: collapsing the two contracts, and
dropping the 3-byte branch's overlong rejection (the 2-byte row alone missed it,
since each branch carries its own test).
No behaviour change at any door, no signature change, no layout change, nothing to
migrate. -179 lines. System::Text::detail still re-exports both entry points, so
every caller written against the old spelling is unchanged.
Also closes #2282 as MOOT: its subject, UnitySerializationHolder::GetRealObject(),
was removed outright by #2281 under SA-9, so there is no misleading message left to
repair and no replacement text left to defer.
Gate: 17,301 run, 17,301 passed, 0 failed, 0 skipped across 38 executables, GREEN.
docs/Utf8ScalarDecodeSingleDefinition.md1 parent f99c46c commit c079845
13 files changed
Lines changed: 405 additions & 316 deletions
File tree
- docs
- modules
- core/include/System/detail
- globalization
- src/System/Globalization
- tests/System/Globalization
- text-json/src/System/Text/Json
- text
- include/System/Text
- detail
- src/System/Text
- tests/System/Text
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | | - | |
| 12 | + | |
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
22 | 20 | | |
23 | 21 | | |
24 | 22 | | |
| |||
27 | 25 | | |
28 | 26 | | |
29 | 27 | | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
35 | 36 | | |
36 | | - | |
37 | | - | |
38 | | - | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
39 | 49 | | |
40 | | - | |
41 | | - | |
| 50 | + | |
| 51 | + | |
42 | 52 | | |
43 | 53 | | |
44 | 54 | | |
45 | 55 | | |
46 | 56 | | |
47 | 57 | | |
48 | 58 | | |
49 | | - | |
| 59 | + | |
50 | 60 | | |
51 | 61 | | |
52 | 62 | | |
53 | 63 | | |
54 | | - | |
55 | | - | |
| 64 | + | |
| 65 | + | |
56 | 66 | | |
57 | 67 | | |
58 | 68 | | |
59 | 69 | | |
60 | 70 | | |
61 | 71 | | |
62 | | - | |
63 | | - | |
| 72 | + | |
| 73 | + | |
64 | 74 | | |
65 | 75 | | |
66 | 76 | | |
| |||
69 | 79 | | |
70 | 80 | | |
71 | 81 | | |
72 | | - | |
| 82 | + | |
73 | 83 | | |
74 | | - | |
75 | 84 | | |
76 | | - | |
| 85 | + | |
77 | 86 | | |
78 | 87 | | |
79 | | - | |
80 | | - | |
81 | | - | |
| 88 | + | |
| 89 | + | |
82 | 90 | | |
83 | 91 | | |
84 | 92 | | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
85 | 121 | | |
86 | 122 | | |
87 | 123 | | |
| |||
Lines changed: 19 additions & 47 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
| |||
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | 18 | | |
23 | 19 | | |
24 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
25 | 34 | | |
26 | 35 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
40 | | - | |
41 | | - | |
42 | | - | |
43 | | - | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
67 | 39 | | |
68 | | - | |
69 | | - | |
| 40 | + | |
| 41 | + | |
70 | 42 | | |
71 | 43 | | |
72 | 44 | | |
| |||
0 commit comments