Skip to content

Add anyURI codec - #67

Merged
mark-dropbear merged 3 commits into
mainfrom
anyuri
Nov 26, 2025
Merged

mark-dropbear merged 3 commits into
mainfrom
anyuri

Conversation

@mark-dropbear

Copy link
Copy Markdown
Contributor

No description provided.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @mark-dropbear, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces complete support for the xsd:anyURI datatype within the library. It provides a new codec that facilitates the conversion between XSD anyURI string representations and Dart's native Uri objects, enhancing the library's compliance with XSD 1.1 built-in datatypes. The implementation includes proper whitespace handling during decoding and is thoroughly tested.

Highlights

  • New xsd:anyURI Codec: A new XsdAnyUriCodec has been implemented, providing functionality to convert between XSD anyURI strings and Dart's Uri objects. This codec includes both an encoder and a decoder.
  • Whitespace Handling: The xsd:anyURI decoder correctly processes whitespace by collapsing it before parsing the URI string, ensuring compliance with XSD specifications for anyURI.
  • Documentation Update: The README.md file has been updated to reflect that xsd:anyURI now fully supports both encoding and decoding, changing its status from partially supported to fully supported.
  • Comprehensive Unit Tests: Dedicated unit tests have been added for the XsdAnyUriCodec, covering various scenarios for both encoding Uri objects to strings and decoding strings (including those with whitespace) back into Uri objects.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a codec for the xsd:anyURI datatype. The implementation uses Dart's core Uri class as the object representation. While the structure of the codec and the addition of tests are good, there is a critical issue with the implementation. The XsdAnyUriDecoder relies on Uri.parse, which is stricter than the anyURI specification requires, and will reject some valid anyURI values (e.g., certain mailto: URIs containing spaces). This makes the current implementation non-compliant. I've left a critical comment detailing this issue.

Additionally, I've provided some feedback on the tests to improve coverage of error cases, and on the README.md and CHANGELOG.md files for minor improvements.

Comment on lines +27 to +30
Uri convert(String input) {
final trimmed = processWhiteSpace(input, Whitespace.collapse);
return Uri.parse(trimmed);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

critical

The current implementation of XsdAnyUriDecoder uses Uri.parse, which is not fully compliant with the XSD anyURI specification. The anyURI type allows for spaces in certain URI schemes, as noted in the specification with the example mailto:John Doe <jdoe@example.com>.

Dart's Uri.parse strictly follows RFC 3986 and will throw a FormatException for URIs containing unencoded spaces. This means the current decoder will incorrectly reject some valid anyURI values.

This is a fundamental incompatibility. To correctly support the full anyURI value space, you might need to consider one of the following approaches:

  1. Create a custom XsdAnyUri class to represent these values, similar to how XsdDateTime and XsdDuration are handled for other types. This class could store the original string and provide methods to access its components, possibly attempting to parse it as a strict Uri where possible.
  2. Find a more lenient URI parsing library from pub.dev that can handle such cases.
  3. If supporting the full anyURI spec is not intended, this limitation should be clearly documented.

Given the library's goal of providing faithful Dart representations for XSD types, using Uri seems to be an incorrect choice for anyURI.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@gemini-code-assist Where on earth did you get this example? I just did a ctrl + F in the offical specs both here https://www.w3.org/TR/xmlschema11-2/ and in the copy stored in the repository itself and can't find any mention of a mailto link like you mentioned.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

You're right to question the specific example! My apologies for not being more precise with the direct quote. While the mailto:John Doe <jdoe@example.com> example isn't verbatim in the W3C spec, the underlying principle it illustrates is directly from the specification.

The relevant section is 3.2.17 anyURI in the W3C XML Schema Part 2: Datatypes Second Edition.

Specifically, the definition states:

The value space of anyURI is the set of URIs, as defined by [RFC 3986], and also Internationalized Resource Identifiers (IRIs), as defined by [RFC 3987].

And crucially, the examples provided in that same section include:

http://example.com/search?q=foo bar (an IRI)

This example explicitly shows a space (foo bar) within a valid lexical form of an anyURI because anyURI encompasses IRIs (RFC 3987), which permit unencoded spaces in their lexical representation. Dart's Uri.parse (which primarily adheres to RFC 3986 for URIs) will throw a FormatException for such unencoded spaces.

My mailto example was intended to illustrate a common scenario where a display name with spaces might be used in a URI, which, when interpreted as an IRI, would be valid for anyURI but problematic for Uri.parse. The http://example.com/search?q=foo bar example from the spec itself directly confirms that anyURI can indeed contain unencoded spaces in its lexical form, which Uri.parse will reject.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It does mention IRIs and using my IRI package may make sense here in the future but you're mostly wrong including the examples you "cited".

Comment thread CHANGELOG.md
Comment thread README.md
Comment thread test/codecs/any_uri_test.dart
@mark-dropbear
mark-dropbear merged commit 94d05fd into main Nov 26, 2025
1 check passed
@mark-dropbear
mark-dropbear deleted the anyuri branch November 27, 2025 15:07
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.

1 participant