From 677e304ce76e81c54eadd4c2c37f9f3a17bd037a Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 31 Aug 2023 15:22:51 +0200 Subject: [PATCH] Ignore null-chars when using structTree-data in the viewer Testing the `tagged_stamp.pdf` document locally in the viewer, I noticed that e.g. the /Alt entry for the StampAnnotation contains "Secondary text for stamp\u0000". Elsewhere in the viewer we're skipping null-chars and it's easy enough to do that in the `StructTreeLayerBuilder` class as well. (Note that we generally let the API itself return the data as-is.) --- web/struct_tree_layer_builder.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/web/struct_tree_layer_builder.js b/web/struct_tree_layer_builder.js index 997fac3397045b..ce3104ecb6ebb6 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,13 @@ 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)); } }