Skip to content

Commit b9b9546

Browse files
dani-polaniclaude
andcommitted
fix(share): keep the merge char when it is the only changed setting
The compact wire wrote `mg` only alongside another non-default setting, so a link where only the join character changed decoded back to `+`. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent bdca050 commit b9b9546

2 files changed

Lines changed: 11 additions & 3 deletions

File tree

‎bitext/src/lib/serialization/compact-v4.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ function settingsToCompact(rounded: VisualSettingsV2): CompactSettings4 | undefi
7575
if (rounded.background !== def.background) {
7676
o.bg = rounded.background === 'dark' ? 1 : 0;
7777
}
78-
const keysBeforeFinalize = Object.keys(o).length;
79-
if (keysBeforeFinalize > 0) {
78+
// Decoding treats a present `s` without `mg` as "no merge char", so any emitted `s` carries it.
79+
if (Object.keys(o).length > 0 || rounded.tokenMergeChar !== def.tokenMergeChar) {
8080
o.mg = rounded.tokenMergeChar;
8181
}
82-
return keysBeforeFinalize > 0 ? sortKeys(o) : undefined;
82+
return Object.keys(o).length > 0 ? sortKeys(o) : undefined;
8383
}
8484

8585
function compactToVisualSettings(s: CompactSettings4 | undefined): VisualSettingsV2 {

‎bitext/src/lib/serialization/serialization-roundtrip.test.ts‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,14 @@ describe('compact v4 encode/decode (current share format)', () => {
284284
expect(decoded.settings.tokenSplitChars).toBe('.');
285285
});
286286

287+
it('round-trip: a changed merge char survives when it is the only non-default setting', () => {
288+
const base = migrate({});
289+
for (const tokenMergeChar of ['_', '']) {
290+
const s: AppStateV2 = { ...base, settings: { ...base.settings, tokenMergeChar } };
291+
expect(decodeState(encodeState(s)).settings.tokenMergeChar).toBe(tokenMergeChar);
292+
}
293+
});
294+
287295
it('round-trip: token link color mode (background)', () => {
288296
const base = migrate({});
289297
const s: AppStateV2 = {

0 commit comments

Comments
 (0)