Add more invalid test cases for parsing entitly declaration#183
Conversation
| class TestCharacterCode < self | ||
| def test_pubid_literal |
There was a problem hiding this comment.
| class TestCharacterCode < self | |
| def test_pubid_literal | |
| class TestPublicIDLiteral < self | |
| def test_invalid_pubid_char |
Could you add PubidLiteral and PubidChar definitions as a comment to understand why this value is invalid?
| class TestCharacterCode < self | ||
| def test_pubid_literal | ||
| exception = assert_raise(REXML::ParseException) do | ||
| REXML::Document.new('<!DOCTYPE root [<!ENTITY foo PUBLIC "あいう" "bar" > ]>') |
There was a problem hiding this comment.
Could you use \U{...} instead of あ to keep this code ASCII only?
|
|
||
| public | ||
|
|
||
| class TestGarbagedValue < self |
There was a problem hiding this comment.
Could you use syntax part name such as GeneralEntityDeclration instead of GarbgedValue for test case name? We want to organize tests based of syntax part not invalid type to avoid missing case.
| class TestGarbagedValue < self | |
| class TestGeneralEntityDeclration < self | |
| # Cover all GEDecl cases in this instead of spreading multiple test cases | |
| def test_invalid_entity_value | |
| def test_invalid_external_id |
Could you also add generic entity declaration definition (and related definitions in this test case) as a comment for easy to understand?
| class TestGarbagedValue < self | ||
| def test_garbaged_after_entity_definition | ||
| exception = assert_raise(REXML::ParseException) do | ||
| REXML::Document.new('<!DOCTYPE root [<!ENTITY "foo" xxx > ]>') |
There was a problem hiding this comment.
Could you use more easy to understand sample values instead of "foo" and xxx?
For example, "valid-name" and invalid-external-id.
|
@kou Thank you for your review. I fixed the tests. |
kou
left a comment
There was a problem hiding this comment.
Could you add comments that which specifications are referred in each test?
| DETAIL | ||
| end | ||
|
|
||
| class TestSystemExternalEntities < self |
There was a problem hiding this comment.
| class TestSystemExternalEntities < self | |
| class TestSystemLiteral < self |
| end | ||
|
|
||
| class TestSystemExternalEntities < self | ||
| def test_invalid_external_entity_before_system_literal |
There was a problem hiding this comment.
| def test_invalid_external_entity_before_system_literal | |
| def test_no_quote |
| class TestSystemExternalEntities < self | ||
| def test_invalid_external_entity_before_system_literal | ||
| exception = assert_raise(REXML::ParseException) do | ||
| REXML::Document.new('<!DOCTYPE root [<!ENTITY valid-name SYSTEM invalid-external-entity "valid-system-literal" > ]>') |
There was a problem hiding this comment.
Is "valid-system-literal" needed here?
| DETAIL | ||
| end | ||
|
|
||
| def test_invalid_external_entity_after_system_literal |
There was a problem hiding this comment.
Could you split this to TestNotationDataDeclaration?
| def test_invalid_external_entity_after_system_literal | |
| def test_not_ndata |
|
|
||
| def test_invalid_external_entity_after_system_literal | ||
| exception = assert_raise(REXML::ParseException) do | ||
| REXML::Document.new('<!DOCTYPE root [<!ENTITY valid-name SYSTEM "valid-system-literal" invalid-external-entity > ]>') |
There was a problem hiding this comment.
not-ndata or something is better than invalid-external-entity because it should be NDATA.
| end | ||
| end | ||
|
|
||
| class TestPublicExternalEntities < self |
There was a problem hiding this comment.
| class TestPublicExternalEntities < self | |
| class TestPublicLiteral < self |
| Line: 1 | ||
| Position: 76 | ||
| Last 80 unconsumed characters: | ||
| valid-name PUBLIC \"あ\" \"valid-system-literal\" > ]> |
This patch will add the test cases to verify that it raises an exception properly when parsing malformed entity declaration. Fix test class names
|
I completely rewrote the code and added tests to cover the specification. |
kou
left a comment
There was a problem hiding this comment.
Could you also add cases that has garbage after valid pattern?
| class TestGeneralEntityDeclaration < self | ||
| # https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-GEDecl |
There was a problem hiding this comment.
Could you use a comment for class instead of a comment in class?
| class TestGeneralEntityDeclaration < self | |
| # https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-GEDecl | |
| # https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-GEDecl | |
| class TestGeneralEntityDeclaration < self |
| class TestEntityValue < self | ||
| def test_no_quote | ||
| # https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-EntityValue |
There was a problem hiding this comment.
| class TestEntityValue < self | |
| def test_no_quote | |
| # https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-EntityValue | |
| # https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-EntityValue | |
| class TestEntityValue < self | |
| def test_no_quote |
| def test_no_quote | ||
| # https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-EntityValue | ||
| exception = assert_raise(REXML::ParseException) do | ||
| REXML::Document.new('<!DOCTYPE root [<!ENTITY valid-name invalid-entity-value > ]>') |
There was a problem hiding this comment.
Could you remove needless spaces?
| REXML::Document.new('<!DOCTYPE root [<!ENTITY valid-name invalid-entity-value > ]>') | |
| REXML::Document.new('<!DOCTYPE root [<!ENTITY valid-name invalid-entity-value>]>') |
| DETAIL | ||
| end | ||
|
|
||
| def test_invalid_entity_value |
There was a problem hiding this comment.
Could you use why this is an invalid value for test name instead of test_invalid_entity_value like you did for test_no_quote?
| DETAIL | ||
| end | ||
|
|
||
| class TestExternalId < self |
There was a problem hiding this comment.
| class TestExternalId < self | |
| class TestExternalID < self |
| end | ||
|
|
||
| class TestNDataDeclaration < self | ||
| def test_no_quote |
There was a problem hiding this comment.
Is "no quote" a suitable reason?
I think that NDATA is only the valid keyword.
There was a problem hiding this comment.
Ah, sorry. It is my mistake.
| end | ||
| end | ||
|
|
||
| class TestNDataDeclaration < self |
There was a problem hiding this comment.
Could you also add a test for invalid Name in NDataDecl ::= S 'NDATA' S Name?
|
|
||
| class TestParsedEntityDeclaration < self | ||
| # https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-PEDecl | ||
| class ParsedEntityDefinition < self |
There was a problem hiding this comment.
| class ParsedEntityDefinition < self | |
| class TestParsedEntityDefinition < self |
| class TestEntityValue < self | ||
| class TestEntityValue < self |
There was a problem hiding this comment.
Ah, sorry. It is my mistake.
| def test_unnecessary_ndata_declaration | ||
| # https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-PEDef | ||
| exception = assert_raise(REXML::ParseException) do | ||
| REXML::Document.new('<!DOCTYPE root [<!ENTITY % valid-name "valid-entity-value" "NDATA" valid-ndata-value > ]>') |
There was a problem hiding this comment.
| REXML::Document.new('<!DOCTYPE root [<!ENTITY % valid-name "valid-entity-value" "NDATA" valid-ndata-value > ]>') | |
| REXML::Document.new('<!DOCTYPE root [<!ENTITY % valid-name "valid-entity-value" NDATA valid-ndata-value > ]>') |
BTW, should we use the ExternalID NDataDecl? part instead of the EntityValue part in EntityDef ::= EntityValue | ExternalID NDataDecl?)? If we want to use the EntityValue part, we should use "garbage" or something instead of ndata_declaration because all contents (including NDataDecl) are invalid after the EntityValue.
There was a problem hiding this comment.
Make sence.
We should make sure to check that any unnecessary NDataDecl after EntityValue will raise an exception.
otegami
left a comment
There was a problem hiding this comment.
Thank you for adding test cases which follows XML's entity declarations.
Should we test PEReference or Reference which are included in EntityValue although those test cases might be out of scope ?
And also, how about adding the following test cases?
- Using single quotes
- Using mixed quotes (
' dummy "or" dummy ') - Removing necessary spaces
| DETAIL | ||
| end | ||
|
|
||
| def test_unnecessary_ndata_declaration |
There was a problem hiding this comment.
Could you move this to TestEntityDefinition and use test_entity_value_and_notation_data_declaration?
This test case is for EntityValue not EntityDef.
otegami
left a comment
There was a problem hiding this comment.
Thanks for implementing it. Although I made a few comments, it looks good overall !
| # https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-ExternalID | ||
| class TestExternalID < self | ||
| # https://www.w3.org/TR/2006/REC-xml11-20060816/#NT-SystemLiteral | ||
| class TestSystemLiteral < self |
There was a problem hiding this comment.
How about adding the cases that there is no SystemLiteral ?
There was a problem hiding this comment.
Thanks. I added the test cases at 8b42c31
Co-authored-by: takuya kodama <a.s.takuya1026@gmail.com>
otegami
left a comment
There was a problem hiding this comment.
It looks nice to me, though I left a small comment 👍🏾
|
|
||
| def test_mixed_quote | ||
| exception = assert_raise(REXML::ParseException) do | ||
| REXML::Document.new('<!DOCTYPE root [<!ENTITY valid-name "invalid-entity-value\'>]>') |
| Line: 1 | ||
| Position: 61 | ||
| Last 80 unconsumed characters: | ||
| valid-name \"invalid-entity-value'>]> |
There was a problem hiding this comment.
Do we need \ before " in here document?
There was a problem hiding this comment.
The escapes are unnecessary.
I removed them at 4bada10
Co-authored-by: takuya kodama <a.s.takuya1026@gmail.com>
|
Thanks. |
|
This patch will add the test cases to verify that it raises an exception properly when parsing malformed entity declaration.