Skip to content

Commit

Permalink
URL encode repeated characters of invalid lines
Browse files Browse the repository at this point in the history
ref #688
  • Loading branch information
frostburn committed May 18, 2024
1 parent 8b01f59 commit 441cd18
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 12 deletions.
9 changes: 9 additions & 0 deletions src/__tests__/url-encode.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ describe('URL encoder', () => {
const expected = ['3/2', 'foo', 'BAR', '2/1']
expect(arraysEqual(decodeLines('3F2_EfEoEo_EBAER_2F1'), expected)).toBeTruthy()
})

it('can encode repeated L characters in invalid lines', () => {
const lines = ['sLL', '9/8', '3/2', '2/1']
expect(encodeLines(lines)).toBe('EsELEL_9F8_3F2_2F1')
})

it('can decode repeated L characters in invalid lines', () => {
expect(decodeLines('EsELEL_9F8_3F2_2F1')).toEqual(['sLL', '9/8', '3/2', '2/1'])
})
})

describe('URL decoder', () => {
Expand Down
18 changes: 9 additions & 9 deletions src/url-encode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ function decodeDigits(digits: string) {

function encodeLine(scaleLine: string) {
scaleLine = scaleLine
.replace(ESCAPE, ESCAPE + ESCAPE)
.replace(FRACTION, ESCAPE + FRACTION)
.replace(COMMA, ESCAPE + COMMA)
.replace(BACKSLASH, ESCAPE + BACKSLASH)
.replace(SPACE, ESCAPE + SPACE)
.replace(LEFT_ANGLE_BRACKET, ESCAPE + LEFT_ANGLE_BRACKET)
.replace(RIGHT_ANGLE_BRACKET, ESCAPE + RIGHT_ANGLE_BRACKET)
.replace(LEFT_SQUARE_BRACKET, ESCAPE + LEFT_SQUARE_BRACKET)
.replace(PLUS, ESCAPE + PLUS)
.replaceAll(ESCAPE, ESCAPE + ESCAPE)
.replaceAll(FRACTION, ESCAPE + FRACTION)
.replaceAll(COMMA, ESCAPE + COMMA)
.replaceAll(BACKSLASH, ESCAPE + BACKSLASH)
.replaceAll(SPACE, ESCAPE + SPACE)
.replaceAll(LEFT_ANGLE_BRACKET, ESCAPE + LEFT_ANGLE_BRACKET)
.replaceAll(RIGHT_ANGLE_BRACKET, ESCAPE + RIGHT_ANGLE_BRACKET)
.replaceAll(LEFT_SQUARE_BRACKET, ESCAPE + LEFT_SQUARE_BRACKET)
.replaceAll(PLUS, ESCAPE + PLUS)

scaleLine = scaleLine
.replace(/\//g, FRACTION)
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.app.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
}
},
"lib": ["es2021"]
}
}
3 changes: 2 additions & 1 deletion tsconfig.node.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"composite": true,
"module": "ESNext",
"moduleResolution": "Bundler",
"types": ["node"]
"types": ["node"],
"lib": ["es2021"]
}
}
1 change: 0 additions & 1 deletion tsconfig.vitest.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"exclude": [],
"compilerOptions": {
"composite": true,
"lib": [],
"types": ["node", "jsdom"]
}
}

0 comments on commit 441cd18

Please sign in to comment.