Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix viewer utils in order to send only valid XML to the server #963

Merged
merged 1 commit into from
May 16, 2024

Conversation

pau-sala-at-wiris
Copy link
Contributor

@pau-sala-at-wiris pau-sala-at-wiris commented May 13, 2024

Description

Some user inputs were causing the server to fail due to malformed XML. When retrieving MathML, the generated text is transformed into HTML, which is not 100% compatible with XML. The current solution uses the browser's native XMLParser to transform HTML into XML and ensures that only valid XML is sent to the server.

Steps to reproduce

Unit tests

  • Run unit tests in this package with: yarn jest .

Ui

  • Open the html-viewer
  • Paste some problematic formulas to text-box and check an image is generated with no errors:
    • <math xmlns="http://www.w3.org/1998/Math/MathML"><mo mathvariant="bold" mathcolor="#7F0000" mathsize="48px">&#xAB;</mo><mo mathvariant="bold" mathcolor="#7F0000" mathsize="48px">&lt;</mo><mo mathvariant="bold" mathcolor="#7F0000" mathsize="48px">&#xBB;</mo><mo mathvariant="bold" mathcolor="#7F0000" mathsize="48px">&gt;</mo><mo mathvariant="bold" mathcolor="#7F0000" mathsize="48px">&#xA7;</mo><mo mathvariant="bold" mathcolor="#7F0000" mathsize="48px">&amp;</mo><mo mathvariant="bold" mathcolor="#7F0000" mathsize="48px">&#xA8;</mo><mo mathvariant="bold" mathcolor="#7F0000" mathsize="48px">&quot;</mo><mo mathvariant="bold" mathcolor="#7F0000" mathsize="48px">'</mo><mo mathvariant="bold" mathcolor="#7F0000" mathsize="48px">'</mo></math>
    • <math><mn mathcolor="red">&quot;4</mn><mo>×</mo><mi>x</mi></math>

#taskid 45734

Changes.md

fix: change htmlEntitiesToXmlEntities' implementation in order to assure only valid XML

@pau-sala-at-wiris pau-sala-at-wiris self-assigned this May 13, 2024
@usantos-at-wiris usantos-at-wiris changed the title KB-45734: Fix viewer utils in order to send only valid xtml to the server KB-45734: Fix viewer utils in order to send only valid XML to the server May 13, 2024
@usantos-at-wiris
Copy link
Contributor

Great way to solve it! Good job!

@usantos-at-wiris usantos-at-wiris changed the base branch from stable to master May 13, 2024 14:06
packages/viewer/src/mathml.ts Outdated Show resolved Hide resolved
packages/viewer/src/utils.spec.ts Outdated Show resolved Hide resolved
packages/viewer/src/utils.ts Outdated Show resolved Hide resolved
@carla-at-wiris carla-at-wiris changed the title KB-45734: Fix viewer utils in order to send only valid XML to the server Fix viewer utils in order to send only valid XML to the server May 13, 2024
Copy link
Contributor

@carla-at-wiris carla-at-wiris left a comment

Choose a reason for hiding this comment

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

Some MathML had corrupted character that needed to be changed, even though the test did not raise errors when transforming the MathML to XML.

Information taken from:

packages/viewer/src/utils.spec.ts Outdated Show resolved Hide resolved
packages/viewer/src/utils.spec.ts Outdated Show resolved Hide resolved
packages/viewer/src/utils.spec.ts Outdated Show resolved Hide resolved
packages/viewer/src/utils.spec.ts Outdated Show resolved Hide resolved
packages/viewer/src/utils.spec.ts Outdated Show resolved Hide resolved
packages/viewer/src/utils.spec.ts Outdated Show resolved Hide resolved
packages/viewer/src/utils.spec.ts Outdated Show resolved Hide resolved
packages/viewer/src/utils.spec.ts Outdated Show resolved Hide resolved
packages/viewer/src/utils.spec.ts Outdated Show resolved Hide resolved
packages/viewer/src/utils.spec.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@jgonzalez-at-wiris jgonzalez-at-wiris left a comment

Choose a reason for hiding this comment

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

Buen trabajo!

@carla-at-wiris carla-at-wiris merged commit c7c460b into master May 16, 2024
13 checks passed
@xjiang-at-wiris xjiang-at-wiris deleted the KB-45734 branch May 16, 2024 15:33
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.

None yet

5 participants