Skip to content

Commit

Permalink
include brackets in encoded url chars
Browse files Browse the repository at this point in the history
  • Loading branch information
tailuge committed Jun 18, 2024
1 parent 0a38025 commit edca3f1
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 19 deletions.
4 changes: 2 additions & 2 deletions dist/diagram.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
"@testing-library/dom": "10.1.0",
"@types/chai": "4.3.16",
"@types/jest": "^29.5.12",
"@types/node": "20.14.2",
"@types/node": "20.14.5",
"@types/three": "0.165.0",
"chai": "4.x",
"ini": "4.1.3",
Expand Down
21 changes: 10 additions & 11 deletions src/events/recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,7 @@ export class Recorder {
currentBreak.score = breakScore
const text = `break(${breakScore})`
const serialisedShot = JSON.stringify(currentBreak)
console.log(`raw:${serialisedShot}`)
const compressed = JSONCrush.crush(serialisedShot)
console.log(`crushed:${compressed}`)
console.log(`encoded:${encodeURIComponent(compressed)}`)
console.log(`decoded:${decodeURIComponent(encodeURIComponent(compressed))}`)

const uncompressed = JSONCrush.uncrush(decodeURIComponent(encodeURIComponent(compressed)))
console.log(`uncompressed:${uncompressed}`)
console.log(serialisedShot == uncompressed)
this.generateLink(text, compressed, "black")
if (breakScore >= 4) {
this.generateHiScoreLink(compressed)
Expand All @@ -171,8 +163,7 @@ export class Recorder {
}

private generateLink(text, state, colour) {
const shotUri = `${this.replayUrl}${encodeURIComponent(state)}`
console.log(`encoded:${shotUri}`)
const shotUri = `${this.replayUrl}${this.fullyEncodeURI(state)}`
const shotLink = `<a class="pill" style="color: ${colour}" target="_blank" href="${shotUri}">${text}</a>`
this.container.eventQueue.push(new ChatEvent(null, `${shotLink}`))
}
Expand All @@ -181,8 +172,16 @@ export class Recorder {
const text = "hi score 🏆"
const shotUri = `${this.hiScoreUrl}?ruletype=${
this.container.rules.rulename
}&state=${encodeURIComponent(state)}`
}&state=${this.fullyEncodeURI(state)}`
const shotLink = `<a class="pill" target="_blank" href="${shotUri}">${text}</a>`
this.container.eventQueue.push(new ChatEvent(null, `${shotLink}`))
}

private fullyEncodeURI(uri) {
return encodeURIComponent(uri)
.replace(/\(/g,'%28')
.replace(/\)/g,'%29')
.replace(/\!/g,'%21')
.replace(/\*/g,'%2A')
}
}
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -957,10 +957,10 @@
dependencies:
undici-types "~5.26.4"

"@types/node@20.14.2":
version "20.14.2"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.14.2.tgz#a5f4d2bcb4b6a87bffcaa717718c5a0f208f4a18"
integrity sha512-xyu6WAMVwv6AKFLB+e/7ySZVr/0zLCzOa7rSpq6jNwpqOrUbcACDWC+53d4n2QHOnDou0fbIsg8wZu/sxrnI4Q==
"@types/node@20.14.5":
version "20.14.5"
resolved "https://registry.yarnpkg.com/@types/node/-/node-20.14.5.tgz#fe35e3022ebe58b8f201580eb24e1fcfc0f2487d"
integrity sha512-aoRR+fJkZT2l0aGOJhuA8frnCSoNX6W7U2mpNq63+BxBIj5BQFt8rHy627kijCmm63ijdSdwvGgpUsU6MBsZZA==
dependencies:
undici-types "~5.26.4"

Expand Down

0 comments on commit edca3f1

Please sign in to comment.