-
Notifications
You must be signed in to change notification settings - Fork 43
Create tests for internal entities & revise existing noResolve tests #334
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
Draft
boswelja
wants to merge
6
commits into
pdvrieze:master
Choose a base branch
from
boswelja:expandentity-testing
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
37fb450
Create tests for internal entities & revise existing noResolve tests
boswelja 608c334
Update test cases
boswelja b49a829
Create parser tests
boswelja c82c228
Create parser tests
boswelja b127858
Update docs
boswelja 5633172
Update IXmlStreaming.kt
boswelja File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -275,6 +275,34 @@ abstract class TestCommonReader { | |
| } | ||
| } | ||
|
|
||
| protected fun testInternalEntities(createReader: (String) -> XmlReader) { | ||
| val text = """ | ||
| <!DOCTYPE Test [ | ||
| <!ENTITY helloWorld "Hello, world!"> | ||
| <!ENTITY foo "Foo"> | ||
| <!ENTITY bar "Bar"> | ||
| <!ENTITY baz "Baz"> | ||
| ]> | ||
| <Test>&helloWorld;</Test> | ||
| """.trimIndent() | ||
| val reader = createReader(text) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It may be worthwhile to change this to have a parameter on whether entities are (auto)expanded. |
||
|
|
||
| var event = reader.next() | ||
| if (event == EventType.START_DOCUMENT) event = reader.next() | ||
| assertEquals(EventType.DOCDECL, event) | ||
| // There should probably be internal entity decl events here, but we only get whitespace... | ||
| do { | ||
| event = reader.next() | ||
| } while (event == EventType.IGNORABLE_WHITESPACE) | ||
| // Start element event for <Test> | ||
| reader.next() | ||
| // Should be the text within the element | ||
| event = reader.next() | ||
| assertEquals(EventType.ENTITY_REF, event) | ||
| assertEquals("Hello, world!", reader.text) | ||
| assertEquals("helloWorld", reader.localName) | ||
| } | ||
|
|
||
| protected abstract fun createReader(xml: String): XmlReader | ||
|
|
||
| @Test | ||
|
|
@@ -339,6 +367,11 @@ abstract class TestCommonReader { | |
| } | ||
| } | ||
|
|
||
| @Test | ||
| open fun testInternalEntities() { | ||
| testInternalEntities(::createReader) | ||
| } | ||
|
|
||
| /** | ||
| * Test that triggers invalid handling of `]]>` inside attribute values. #266 | ||
| */ | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe mention that "entities in attribute values are always expanded. If the reference in an attribute is unrecognized this will always result in an exception" (new behaviour, old one was an empty string).
For XML wellformedness it is required that entity references reference declared entities. So throwing an exception would be valid (even though the parser is not quite meeting the requirements of even a non-validating parser.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I pushed an update, what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks good. Maybe the test could have a parameter to
createReaderto determine whether entities are expanded. Alternatively some of the per format subclasses could be duplicated with different factory functions.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good - just to clarify, the parameter on
createReadershould behave the same as the one here right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Basically yes.