Skip to content

Commit

Permalink
Fix issue with Iri rule not handling URLs without trailing slash
Browse files Browse the repository at this point in the history
  • Loading branch information
althonos committed Sep 28, 2020
1 parent 4bd44dc commit 1042068
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/grammar.pest
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,11 @@ ResourcePropertyValue = { RelationId ~ Id }

Iri = @{ IriScheme ~ ":" ~ IriHierPart ~ ("?" ~ IriQuery)? ~ ("#" ~ IriFragment)? }

// NB(@althonos): IriPathAbEmpty is not mandatory if we reach the end of input
// here to allow URLs to hosts without trailing slashes, e.g.
/// 'http://example.com', which would be rejected otherwise.
IriHierPart = {
("//" ~ IriAuthority ~ IriPathAbempty )
("//" ~ IriAuthority ~ (IriPathAbempty | EOI) )
| IriPathAbsolute
| IriPathRootless
| IriPathEmpty
Expand All @@ -411,7 +414,7 @@ IriPathAbempty = ${ ("/" ~ IriSegment)+ }
IriPathAbsolute = ${ "/" ~ (IriSegmentNz ~ ("/" ~ IriSegment)* )? }
IriPathNoScheme = ${ IriSegmentNzNc ~ ("/" ~ IriSegment)* }
IriPathRootless = ${ IriSegmentNz ~ ("/" ~ IriSegment)* }
IriPathEmpty = ${ "0" ~ IriIpChar}
IriPathEmpty = ${ "" }

IriSegment = @{ IriIpChar* }
IriSegmentNz = @{ IriIpChar+ }
Expand Down
23 changes: 23 additions & 0 deletions tests/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ fn term_frame() {
test_parse!(TermFrame, "[Term]\n id: TEST:001\ndef: \"test item\" []\n");
test_parse!(TermFrame, "[Term]\nid: TEST:001\n def: \"test item\" []\n");
test_parse!(TermFrame, " [Term]\nid: TEST:001\ndef: \"test item\" []\n");
// url id
test_parse!(TermFrame, "[Term]\nid: http://example.com\ndef: \"test item\" []\n");
test_parse!(TermFrame, "[Term]\nid: http://example.com/\ndef: \"test item\" []\n");
}

#[test]
Expand Down Expand Up @@ -134,3 +137,23 @@ fn property_value() {
test_parse!(ResourcePropertyValue, "foaf:depiction http://purl.obolibrary.org/obo/plana/images/Stage2.png");
test_not_parse!(LiteralPropertyValue, "foaf:depiction http://purl.obolibrary.org/obo/plana/images/Stage2.png");
}

#[test]
fn iri() {
test_parse!(Iri, "http://example.com");
test_parse!(Iri, "http://example.com/");
test_parse!(Iri, "http://example.com/with/a/path");
test_parse!(Iri, "http://user:pass@example.com");
test_parse!(Iri, "http://user:pass@example.com/");
test_parse!(Iri, "http://user:pass@example.com/with/a/path");
}

#[test]
fn term_clause() {
test_parse!(TermClause, "xref: http://example.com");
test_parse!(TermClause, "xref: http://example.com/");
test_parse!(TermClause, "xref: http://example.com/with/a/path");
test_parse!(TermClause, "xref: http://user:pass@example.com");
test_parse!(TermClause, "xref: http://user:pass@example.com/");
test_parse!(TermClause, "xref: http://user:pass@example.com/with/a/path");
}

0 comments on commit 1042068

Please sign in to comment.