FIX: ensures lightbox sends valid color to react-native (#22598)

Prior to this commit the `setSiteThemeColor` could mistakenly receive a color with a leading `#` which would cause an invalid color to be send to `postRNWebviewMessage` and would eventually cause a crash if we try to interpolate between this color and another.
This commit is contained in:
Joffrey JAFFEUX 2023-07-13 18:37:52 +02:00 committed by GitHub
parent 56e792df9b
commit ee3bdab61d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 1 deletions

View File

@ -6,7 +6,7 @@ export async function getSiteThemeColor() {
}
export async function setSiteThemeColor(color = "000000") {
const _color = `#${color}`;
const _color = `#${color.replace(/^#*/, "")}`;
const siteThemeColor = document.querySelector('meta[name="theme-color"]');

View File

@ -55,5 +55,15 @@ module(
querySelectorSpy.restore();
});
test("invalid color given", async function (assert) {
await setSiteThemeColor("##0000ff");
assert.strictEqual(
document.querySelector('meta[name="theme-color"]').content,
"#0000ff",
"converts to a the correct theme color"
);
});
}
);