Skip to content

Commit

Permalink
Ignore null-chars when using structTree-data in the viewer
Browse files Browse the repository at this point in the history
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.)
  • Loading branch information
Snuffleupagus committed Aug 31, 2023
1 parent 20b0be9 commit 677e304
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions web/struct_tree_layer_builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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));
}
}

Expand Down

0 comments on commit 677e304

Please sign in to comment.