Skip to content

Fix relative IRIs containing a forward slash before a colon#80

Closed
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-relative-iri-parsing
Closed

Fix relative IRIs containing a forward slash before a colon#80
Copilot wants to merge 2 commits intomasterfrom
copilot/fix-relative-iri-parsing

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Mar 4, 2026

The relative-to-absolute-iri library treats any value containing a colon as absolute, without validating that the pre-colon segment is a valid URI scheme. Per RFC 3986, a scheme is ALPHA *( ALPHA / DIGIT / "+" / "-" / "." ) — slashes are forbidden — so x/y:z is unambiguously a relative IRI and must be resolved against the base IRI.

Changes

  • lib/RdfXmlParser.ts: In valueToUri, detect when a slash precedes the first colon (ruling out a valid scheme). For such values, temporarily encode all colons as \u0000 (null character, illegal in XML and therefore safe as a sentinel), resolve against the base IRI, then restore the colons.
<!-- base IRI: https://example.com/base/ -->
<default:C rdf:about="x/y:z"/>
<!-- Previously resolved to: x/y:z (incorrect — treated as absolute) -->
<!-- Now resolves to: https://example.com/base/x/y:z (correct) -->
  • test/RdfXmlParser-test.ts: Added unit tests for valueToUri covering slash-before-colon resolution (with/without trailing slash on base, multiple colons), and an integration test parsing a full RDF/XML document with such a relative IRI.
Original prompt

This section details on the original issue you should resolve

<issue_title>Relative IRIs containing a forward slash and a colon</issue_title>
<issue_description>Files that contain rdf:about="{x}/{y}:{z}" are incorrectly parsed ATM.

Example dataset:

<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns="https://example.com/default/"
         xml:base="https://example.com/base/">
  <C rdf:about="x/y:z">
  </C>
</rdf:RDF>

The expected behavior / reproducible with Rapper is to parse the above as:

<https://example.com/base/x/y:z> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <https://example.com/default/C>.

Maybe x/y:z is considered a full IRI by the parser. If so, this is incorrect because the scheme component is not allowed to contain a forward slash (/). Therefore, x/y:z should be considered a relative IRI which must be made absolute.
</issue_description>

<agent_instructions>Could you fix this issue and provide a unit test for it?</agent_instructions>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Co-authored-by: rubensworks <440384+rubensworks@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix parsing of relative IRIs with forward slash and colon Fix relative IRIs containing a forward slash before a colon Mar 4, 2026
@coveralls
Copy link
Copy Markdown

Pull Request Test Coverage Report for Build 22686555487

Details

  • 5 of 5 (100.0%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 21170362124: 0.0%
Covered Lines: 372
Relevant Lines: 372

💛 - Coveralls

@rubensworks
Copy link
Copy Markdown
Member

Replaced by rubensworks/relative-to-absolute-iri.js#28

@rubensworks rubensworks closed this Mar 5, 2026
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.

Relative IRIs containing a forward slash and a colon

3 participants