Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unicode parsing #2030

Merged
merged 2 commits into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions packages/core/src/i18n.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,4 +331,16 @@ describe("I18n", () => {
expect(missing).toHaveBeenCalledWith("en", "missing")
})
})

it("._ should parse unicode sequences even if the same string goes twice in a row", () => {
const messages = {
"Software development": "Software\\u00ADentwicklung",
}
const i18n = setupI18n({
locale: "de",
messages: { de: messages },
})
expect(i18n._("Software development")).toEqual("Software­entwicklung")
expect(i18n._("Software development")).toEqual("Software­entwicklung")
})
})
10 changes: 10 additions & 0 deletions packages/core/src/interpolate.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,4 +201,14 @@ describe("interpolate", () => {
"Hey Joeª!"
)
})

it("should not crash on a unicode sequences if the same string goes twice in a row", () => {
const cache = compile("Hey {name}!")
expect(interpolate(cache, "en", [])({ name: "Joe\\xaa" })).toEqual(
"Hey Joeª!"
)
expect(interpolate(cache, "en", [])({ name: "Joe\\xaa" })).toEqual(
"Hey Joeª!"
)
})
})
2 changes: 1 addition & 1 deletion packages/core/src/interpolate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { isString } from "./essentials"
import { unraw } from "unraw"
import { CompiledIcuChoices } from "@lingui/message-utils/compileMessage"

export const UNICODE_REGEX = /\\u[a-fA-F0-9]{4}|\\x[a-fA-F0-9]{2}/g
export const UNICODE_REGEX = /\\u[a-fA-F0-9]{4}|\\x[a-fA-F0-9]{2}/

const OCTOTHORPE_PH = "%__lingui_octothorpe__%"

Expand Down
Loading