diff --git a/test/integration/accessibility_spec.js b/test/integration/accessibility_spec.js index b11c0eb5c..4dde9779b 100644 --- a/test/integration/accessibility_spec.js +++ b/test/integration/accessibility_spec.js @@ -169,6 +169,22 @@ describe("accessibility", () => { ); }); + it("must check the aria-label linked to the stamp annotation", async () => { + await Promise.all( + pages.map(async ([browserName, page]) => { + await page.waitForSelector(".structTree"); + + const ariaLabel = await page.$eval( + ".structTree [role='figure']", + el => el.getAttribute("aria-label") + ); + expect(ariaLabel) + .withContext(`In ${browserName}`) + .toEqual("Secondary text for stamp"); + }) + ); + }); + it("must check that the stamp annotation is linked to the struct tree", async () => { await Promise.all( pages.map(async ([browserName, page]) => { diff --git a/web/struct_tree_layer_builder.js b/web/struct_tree_layer_builder.js index 997fac339..5ede61cab 100644 --- a/web/struct_tree_layer_builder.js +++ b/web/struct_tree_layer_builder.js @@ -13,6 +13,8 @@ * limitations under the License. */ +import { removeNullCharacters } from "./ui_utils.js"; + const PDF_ROLE_TO_HTML_ROLE = { // Document level structure types Document: null, // There's a "document" role, but it doesn't make sense here. @@ -102,13 +104,16 @@ class StructTreeLayerBuilder { #setAttributes(structElement, htmlElement) { const { alt, id, lang } = structElement; if (alt !== undefined) { - htmlElement.setAttribute("aria-label", alt); + htmlElement.setAttribute("aria-label", removeNullCharacters(alt)); } if (id !== undefined) { htmlElement.setAttribute("aria-owns", id); } if (lang !== undefined) { - htmlElement.setAttribute("lang", lang); + htmlElement.setAttribute( + "lang", + removeNullCharacters(lang, /* replaceInvisible = */ true) + ); } }