Repository navigation
fix(report): use literal document IDs for PDF controls - #555
Conversation
Address the PDF viewer item in awslabs#476. Keep canvases, load/error messages, page labels and navigation controls reachable for document IDs containing spaces or CSS punctuation. AI-assisted implementation with independent code review. Offline regression cases reproduce 12 failures on dev and all 16 pass here. Full suite: 4117 passed, 13 skipped, 1 xfailed. Safari DOM check passes all 16 cases with PDF.js stubbed; real PDF decoding is not newly tested.
vawsgit
left a comment
There was a problem hiding this comment.
needs changes
The fix is correct. One thing is missing: a CHANGELOG.md entry.
Missing CHANGELOG entry. git diff origin/dev...a91ab9e -- CHANGELOG.md is empty. This fixes a bug a user could hit (the PDF gallery stays on "Loading PDF..." for IDs such as invoice_1.pdf). RELEASING.md requires an entry for that:
Lines 99 to 103 in a91ab9e
Add one bullet under
[Unreleased] > ### Fixed with Refs #476, not a closing keyword, because #476 stays open.
Verified and cleared
- PR body numbers reproduce. The new harness gives 12 failed / 4 passed on
devmain.jsand 16 passed at head. The full suite gives 4117 passed, 13 skipped, 1 xfailed. - Real browser (headless Chrome, merged with current
dev): I tested 12 document IDs, includinginvoice_1.pdf,inv 001,a:b,a"b,</script><script>…,<img onerror>, attribute-breakout and JS-breakout strings, and a U+2028 ID. 12 of 12 viewers loaded and paged. No injected code ran, and the page threw no errors. Ondev, 2 of 12 loaded. The ID only reachesgetElementById,.idandtextContent, so this does not reopen the 1.0.1 (#475) injection fixes. - Mutations: reverting each of the seven lookups is caught (6–12 of 16 cases fail). Setting
isEvalSupported: truefails 16 of 16, so the CVE-2024-4367 mitigation is pinned. - No conflict with
dev. CI has not run on the head commit yet.
Non-blocking (low)
- The Node harness's fake
getElementByIdfinds elements that were never attached, so deletingappendChild(navControls)still passes. test_pdf_document_ids.py:16readsmain.jsfrom the repo path, not the file the reporter embeds.
Add an [Unreleased] > Fixed entry for the PDF viewer lookups, as RELEASING.md asks for a user-visible bug fix. Refs awslabs#476 rather than closing it, since the umbrella issue stays open.
sromoam
left a comment
There was a problem hiding this comment.
Thanks for this, and for adding the CHANGELOG entry so quickly. The fix reads well, and nothing else in main.js builds a selector from a document ID.
Must fix
CHANGELOG.mdnow conflicts withdev: the #478 entry landed in the same spot at the top of### Fixed. Mergingdevand keeping both bullets should be all it takes.
Smaller
- Optional: the headline "loads documents whose IDs are not CSS identifiers" (
CHANGELOG.md:24) is a touch broader than the fix. An ID with a carriage return or NUL still shows no PDF, on this branch and ondev, becausecaptureDocumentFileData(main.js:149-161) keys files by the parsed<strong>text, which the HTML parser normalizes. Not a regression and not something this PR needs to fix. Narrowing the wording (for example "IDs that contain spaces or CSS punctuation") or leaving it for us to track separately are both fine.
Measured against this branch in headless Chrome: with 15 document IDs, including quotes, spaces, :, #, [, </script>, an onerror image tag, attribute and JS string breakouts, U+2028 and CJK, every PDF viewer loaded and paged, and no injected code ran. With dev's main.js, only 3 of the 15 loaded. Once the conflict is resolved and CI is green, this looks good to merge from my side.
vawsgit
left a comment
There was a problem hiding this comment.
needs changes
There is one blocker. CHANGELOG.md conflicts with current dev, so GitHub cannot merge this PR. CI has never run on it either: gh pr checks 555 reports "no checks reported", because the pull_request workflows do not start while the merge ref cannot be built. The code fix is correct. Once the conflict is resolved and CI is green, this PR is good to merge.
Required change
- Merge current
devintofix/476-pdf-element-ids. Keep both the #478 bullet fromdevand this PR's PDF-viewer bullet under[Unreleased] > ### Fixed. See the inline comment onCHANGELOG.md.
Previous review (on a91ab9e)
- Missing CHANGELOG entry: fixed in fe7010f (CHANGELOG.md#L24-L29). The entry is under Unreleased and uses
Refs #476with no closing keyword. That matches the PR covering only item 2 of #476. Butdevhas since added a bullet at the same place, which caused the conflict above. - Low, non-blocking, still open: the Node harness's fake
getElementByIdalso finds elements that were never attached. DeletingpdfContainer.appendChild(navControls);still gives 0/16 failures. - Low, non-blocking, still open:
tests/reporting/html/test_pdf_document_ids.py:16readsmain.jsfrom the repo path, not from the copy the reporter embeds.
What I verified (head 5745260, stickler imported from the PR worktree's src)
- True diff:
git diff origin/dev...touches 6 files. They areCHANGELOG.md,main.js(+8/-7), the new Node harness, the new pytest wrapper and two READMEs. The two "reconcile" merges bring in nothing else. - Node harness:
dev'smain.jsfails 12/16 cases. Head fails 0/16.tests/reporting/htmlgives 184 passed. - Mutation tests:
- Reverting the canvas, loading or error lookup fails 12/16 each.
- Reverting the render-loading, page-info, prev or next lookup fails 6/16 each.
isEvalSupported: truefails 16/16, so the CVE-2024-4367 mitigation is pinned.- Dropping the
display='block'on the canvas or the error element fails 8/16 each.
- Real browser: I generated reports with
EvaluationHTMLReporter.generate_report(...)from real 2-page PDFs. I drove them in headless Chrome with PDF.js 3.11.174 and tried 12 document IDs.- The IDs were:
invoice_1.pdf,inv 001,a:b,a[b],a"b,a#b,請求書,1abc,a\b, a</script>payload, a');...('payload and plaininvoice_1. - Head: 12/12 loaded and paged to "Page 2 of 2". No injected code ran.
dev: 3/12 loaded. The others threwSyntaxError: ... is not a valid selectoror matched nothing.
- The IDs were:
- Full suite (
--extra llm --extra bert): 4197 passed, 3 skipped, 1 xfailed. Ruff check and format pass on the new test, andnode --check main.jspasses. - Merge against base: between the merge base and
dev, only docs and the CHANGELOG changed. There is no narrowed CI matrix, reverted config floor or resurrected code. CI usesubuntu-latest, which has Node, so the new test will run there instead of skipping.
Optional
- The CHANGELOG headline ("IDs that are not CSS identifiers") claims more than the fix covers. IDs containing CR or NUL still produce no PDF item. The cause is
captureDocumentFileData, which keys files by the parsed<strong>text, and this PR did not change it. This is not a regression. Narrowing the wording to "IDs that contain spaces or CSS punctuation" would be accurate.
|
|
||
| ### Fixed | ||
|
|
||
| - **The HTML report's PDF viewer loads documents whose IDs are not CSS |
There was a problem hiding this comment.
Blocker: this bullet conflicts with current dev. A trial git merge --no-commit origin/dev at 5745260 gives CONFLICT (content): Merge conflict in CHANGELOG.md, and that is the only conflicted file. dev (#478, via #550) added its own bullet at the same place under [Unreleased] > ### Fixed. Merge dev and keep both bullets. Until then GitHub blocks the merge and CI does not run on this PR.
Optional: "not CSS identifiers" is broader than the fix. IDs containing CR or NUL still produce no PDF item, through captureDocumentFileData (not touched here). "IDs that contain spaces or CSS punctuation" would be accurate.
|
@vawsgit @sromoam Merged current On the merged tree: |
vawsgit
left a comment
There was a problem hiding this comment.
✅ LGTM!
The only blocker from my previous review is fixed. Merge commit 35a9db4 resolved the CHANGELOG.md conflict with dev. The code is byte-identical to 5745260, which I already verified: git diff 5745260 35a9db4 -- src tests is empty.
Previous review (on 5745260)
- Blocker,
CHANGELOG.mdconflicts withdev: fixed.git merge-tree --write-tree origin/dev 35a9db4reports no conflict. The merge base is thedevtip (8c56dfa).- The #478 bullet from
devis kept word for word. The "Pretty printers" bullet is kept too. - This PR's bullet sits under
[Unreleased] > ### Fixedand still saysRefs #476with no closing keyword (CHANGELOG.md#L30-L37). git diff origin/dev 35a9db4 --statand the three-dot diff list the same 6 files. The merge dropped nothing fromdevand added nothing extra.
- Optional, the CHANGELOG headline claimed too much: fixed. The headline now reads "loads documents whose IDs contain spaces or CSS punctuation".
- Correction to my previous review. I wrote that CI never ran because the merge ref could not be built. That was wrong. The workflow runs on 5745260 and 2b7c362 exist and show
action_required: GitHub was waiting for a maintainer to approve workflows on this fork PR. The runs on 35a9db4 are in the same state.
What I verified (head 35a9db4, stickler imported from the PR worktree's src)
- Node harness:
dev'smain.jsfails 12/16 cases. Head fails 0/16.tests/reporting/htmlgives 184 passed. - Full suite (
--extra llm --extra bert, Python 3.12.13): 4197 passed, 3 skipped, 1 xfailed. - Mutation tests, against all 16 harness cases:
- Reverting the canvas, loading or error lookup fails 12/16 each.
- Reverting the render-loading, page-info, prev or next lookup fails 6/16 each.
isEvalSupported: truefails 16/16, so the CVE-2024-4367 mitigation is pinned.- Removing the canvas
display='block'fails 8/16.
- Real browser: I generated a report with
EvaluationHTMLReporter.generate_report(...)from a real 2-page PDF. I drove it in headless Chrome with PDF.js 3.11.174 and tried 15 document IDs. They includedinv 001,a:b,a[b],a"b,請求書,a\b, an ID containing U+2028,pdf-canvas-nested, and</script>,');...('and<img onerror>payloads.- Head: 15/15 loaded and paged to "Page 2 of 2". No injected code ran.
dev: 5/15 loaded. The others threw... is not a valid selectoror matched nothing.
- No other selector built from a document ID remains in
main.js.canvasId.replace('pdf-canvas-', '')replaces only the first match, sopdf-canvas-nestedworks. - Staleness against
dev: no CI workflow changes, no reverted config, no resurrected code. The CHANGELOG entry sits under[Unreleased], not under the released 1.0.1.
Before merge
- A maintainer must approve the four workflow runs on 35a9db4 (Run Tests, Code Quality, Check Documentation, Security Scan). They show
action_required.
Non-blocking (low, still open)
- The harness's fake
getElementByIdfinds elements that were never attached. DeletingpdfContainer.appendChild(navControls);still gives 0/16 failures, becauseappendChildregisters the child globally whatever its parent is (pdf_document_ids.cjs#L9-L14). tests/reporting/html/test_pdf_document_ids.py:16readsmain.jsfrom the repo path, not from the copy the reporter embeds.
Security Scan ResultsASH Security Scan Report
Scan Metadata
SummaryScanner ResultsThe table below shows findings by scanner, with status based on severity thresholds and dependencies:
Report generated by Automated Security Helper (ASH) at 2026-11-18T23:16:53+00:00 |
Issue #, if available:
Part of #476, item 2 only (PDF viewer canvas lookup). The umbrella issue stays open.
Description of changes:
loadPDFinreporting/html/interactive/main.jslooked up the canvas, loading and error elements with CSS selectors built from the rawdoc_id(getElement(#${canvasId})). Forinvoice_1.pdfthe selector reads as idpdf-canvas-invoice_1plus classpdfand returnsnull; for ids likeinv 001ora:bit throws aSyntaxErrorinsidesetTimeout. Either way the gallery stays on "Loading PDF...".The seven dynamic lookups (initial canvas/loading/error, render completion, page label, previous and next controls) now use
document.getElementByIdwith the literal id, so nodoc_idis ever parsed as a selector. No other behaviour changes.Tests:
tests/reporting/html/test_pdf_document_ids.pydrives the realmain.jsin a Node VM with a minimal DOM (pdf_document_ids.cjs) across plain, dotted, spaced,:and#ids, covering load, page navigation and the failure display. Adds the directory README that AGENTS.md asks for.sticklerimported from this checkout'ssrc).node --checkpasses; repository-wide Ruff has the same 17 findings as unmodified dev.A real-browser check (Safari, PDF.js stubbed offline) gave 4/16 on dev and 16/16 with the patch. Real PDF decoding was not re-tested.
AI-assisted implementation, testing and review.
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Current-base validation (2026-11-13): reconciled dev
7034ec07ddf6084a0541e1c48c3fe8418c737922without rewriting history. Python 3.12.16 full non-integration suite with optional LLM/BERT dependencies: 3,525 passed, 2 skipped, 1 xfailed; repository-wide Ruff and diff checks pass. Tests explicitly import this checkout. Independent merge review found no blocking issues. Hosted workflows still require maintainer authorization. PDF behavior tests use a simulated DOM/PDF.js; this does not claim live-browser visual validation.