← Back to DAGDA | Support | Source: https://github.com/tesseract-ocr/tesseract/pull/4652
Skip to content

Escape input names in ALTO and PAGE XML - #4652

Merged
stweil merged 2 commits into
tesseract-ocr:mainfrom
AryanRG:fix/xml-input-name-escaping
Oct 18, 2026
Merged

stweil merged 2 commits into
tesseract-ocr:mainfrom
AryanRG:fix/xml-input-name-escaping

Conversation

@AryanRG

@AryanRG AryanRG commented Oct 15, 2026

Copy link
Copy Markdown
Contributor

Problem

ALTO fileName and PAGE imageFilename / externalRef wrote the input name
directly into XML. A valid filename containing &, such as
alpha&beta.pgm, therefore produced output that XML parsers rejected.

Change

Use the existing HOcrEscape helper when serializing those three fields. The
PAGE reading-order hash continues to use the raw input name, and ALTO keeps its
existing empty fileName behavior when no name is set.

Add regressions covering:

  • PAGE API imageFilename
  • ALTO renderer fileName
  • PAGE renderer externalRef and imageFilename

Validation

  • All three regressions failed before the production change on the raw &
    output, then passed after the fix.
  • TesseractTest.PAGEXMLMultiPageClosingTags passes.
  • Current-source ALTO and PAGE CLI output for both plain and alpha&beta.pgm
    inputs passes xmllint and Python ElementTree parsing; the special input is
    serialized as &.
  • git diff --check passes.

The complete local baseapi_test binary cannot finish with the available
language-data set: both the unchanged baseline and patched run exit at the same
missing-vie multi-instance case. Running every pre-existing case separately
produces identical pass, skip, failure, and exit classifications before and
after this change.

Escape XML-special characters when serializing ALTO and PAGE input names, while preserving the raw PAGE name for reading-order identity. Add focused regressions for ALTO fileName and PAGE imageFilename/externalRef output.

Assisted-by: Codex and Claude Opus 5.5
@codacy-production

codacy-production Bot commented Oct 15, 2026 •

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 5 complexity · 6 duplication

Metric Results
Complexity 5
Duplication 6

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@stweil
stweil requested a balanced review from Copilot October 18, 2026 18:32

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The focused changes reuse existing escaping logic, include targeted regression coverage, and have no identified blocking issues.

No open issues 🎉

Review effort: Balanced

Comment thread src/api/pagerenderer.cpp Resolved
Comment thread unittest/baseapi_test.cc Resolved
Comment thread unittest/baseapi_test.cc Outdated
Comment on lines +543 to +547
EXPECT_THAT(page,
::testing::Not(HasSubstr("externalRef=\"https://example.test/image?a=1&b=2\"")));
EXPECT_THAT(
page,
::testing::Not(HasSubstr("imageFilename=\"https://example.test/image?a=1&b=2\"")));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These checks are redundant (see the checks directly above) and could be removed.

@stweil stweil left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@stweil
stweil merged commit 565e3bd into tesseract-ocr:main Oct 18, 2026
1 check passed
stweil pushed a commit that referenced this pull request Oct 19, 2026
Escape XML-special characters when serializing ALTO and PAGE input names,
while preserving the raw PAGE name for reading-order identity. Add focused
regressions for ALTO fileName and PAGE imageFilename/externalRef output.

Assisted-by: Codex and Claude Opus 5.5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants