Skip to content

Commit 97ec8e9

Browse files
committed
Strip CR when parsing embedded bitmap schema
On a CRLF checkout (Windows) the embedded schema.txt lines kept a trailing \r, so they never matched the clean paths from WalkType. Merge's dedup then failed and the schema doubled, breaking bundle bitmap schema/bitmap-text on Windows. splitLines now normalizes CRLF. Co-authored-by: Isaac
1 parent b947d68 commit 97ec8e9

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

‎bundle/bitmap/bitmap.go‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,11 @@ func Decode(encoded string) (bits []bool, context uint16, err error) {
246246

247247
// splitLines splits embedded schema bytes into non-empty lines.
248248
func splitLines(b []byte) []string {
249-
s := strings.TrimRight(string(b), "\n")
249+
// Strip CR so a CRLF checkout of the embedded schema.txt (Windows) parses to
250+
// the same clean field paths as WalkType produces; otherwise Merge's dedup
251+
// never matches and the schema doubles.
252+
s := strings.ReplaceAll(string(b), "\r\n", "\n")
253+
s = strings.TrimRight(s, "\n")
250254
if s == "" {
251255
return nil
252256
}

‎bundle/bitmap/bitmap_test.go‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ func TestBitsSetsLeafAndPrefixes(t *testing.T) {
9999
assert.False(t, set["workspace.host"])
100100
}
101101

102+
func TestSplitLinesStripsCRLF(t *testing.T) {
103+
// A CRLF checkout of schema.txt (Windows) must parse to the same clean field
104+
// paths as an LF one, so Merge's dedup matches and the schema does not double.
105+
assert.Equal(t, []string{"variables", "bundle.name"}, splitLines([]byte("variables\r\nbundle.name\r\n")))
106+
assert.Equal(t, []string{"variables", "bundle.name"}, splitLines([]byte("variables\nbundle.name\n")))
107+
}
108+
102109
func TestBitsSetsTelemetryField(t *testing.T) {
103110
schema := []string{"telemetry.select_used"}
104111
bits, err := Bits(config.Root{}, testTelemetry{SelectUsed: true}, schema)

0 commit comments

Comments
 (0)