Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Add decoding of the strings that don't have backslashes (#979)
Olga Bulatffa9525263ce
diff --git a/frontend/src/utils/decode-data.ts b/frontend/src/utils/decode-data.tsindex 02bf31d81..3bb27f71a 100644--- a/frontend/src/utils/decode-data.ts+++ b/frontend/src/utils/decode-data.ts@@ -9,7 +9,11 @@ export const decodeData = (data = ""): string => {if (!data) return ""try {- const regexes = [/\\x([\d\w]{2})/gi, /\\u([\d\w]{4})/gi]+ const regexes = [+ /\\x([\da-f]{2})/gi,+ /\\u([\da-f]{4})/gi,+ /u([\da-f]{4})/gi,+ ]regexes.forEach((regex) => {data = data.replace(regex, (_, grp) =>String.fromCharCode(parseInt(grp, 16))diff --git a/frontend/test/unit/specs/utils/decode-data.spec.js b/frontend/test/unit/specs/utils/decode-data.spec.jsindex 32371cf5c..9451058fe 100644--- a/frontend/test/unit/specs/utils/decode-data.spec.js+++ b/frontend/test/unit/specs/utils/decode-data.spec.js@@ -31,6 +31,12 @@ describe("decodeData", () => {expect(decodeData(data)).toBe("s\u1234\xe9")})+ it("returns decoded string when string does not contain backslash", () => {+ const data = "musu00e9e"++ expect(decodeData(data)).toBe("musée")+ })+it("shouldnt throw exception", () => {const data = "Classic Twill - SlipcoverFabrics.com 100% Cotton"