Repository navigation
Add anyURI codec #67
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
Add anyURI codec #67
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import 'dart:convert'; | ||
|
|
||
| import 'package:xsd/src/helpers/whitespace.dart'; | ||
|
|
||
| /// A [Codec] that converts between XSD `anyURI` strings and [Uri] objects. | ||
| class XsdAnyUriCodec extends Codec<Uri, String> { | ||
| const XsdAnyUriCodec(); | ||
|
|
||
| @override | ||
| Converter<Uri, String> get encoder => const XsdAnyUriEncoder(); | ||
|
|
||
| @override | ||
| Converter<String, Uri> get decoder => const XsdAnyUriDecoder(); | ||
| } | ||
|
|
||
| class XsdAnyUriEncoder extends Converter<Uri, String> { | ||
| const XsdAnyUriEncoder(); | ||
|
|
||
| @override | ||
| String convert(Uri input) => input.toString(); | ||
| } | ||
|
|
||
| class XsdAnyUriDecoder extends Converter<String, Uri> { | ||
| const XsdAnyUriDecoder(); | ||
|
|
||
| @override | ||
| Uri convert(String input) { | ||
| final trimmed = processWhiteSpace(input, Whitespace.collapse); | ||
| return Uri.parse(trimmed); | ||
| } | ||
|
Comment on lines
+27
to
+30
Contributor
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. The current implementation of Dart's This is a fundamental incompatibility. To correctly support the full
Given the library's goal of providing faithful Dart representations for XSD types, using
Contributor
Author
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. @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.
Contributor
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. You're right to question the specific example! My apologies for not being more precise with the direct quote. While the The relevant section is 3.2.17 anyURI in the W3C XML Schema Part 2: Datatypes Second Edition. Specifically, the definition states:
And crucially, the examples provided in that same section include:
This example explicitly shows a space ( My
Contributor
Author
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 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". |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| import 'package:test/test.dart'; | ||
| import 'package:xsd/xsd.dart'; | ||
|
|
||
| void main() { | ||
| group('XsdAnyUriCodec', () { | ||
| const codec = XsdAnyUriCodec(); | ||
|
|
||
| test('should encode valid URI', () { | ||
| expect( | ||
| codec.encode(Uri.parse('http://example.com')), | ||
| 'http://example.com', | ||
| ); | ||
| expect( | ||
| codec.encode(Uri.parse('urn:isbn:1234567890')), | ||
| 'urn:isbn:1234567890', | ||
| ); | ||
| }); | ||
|
|
||
| test('should decode valid URI', () { | ||
| expect( | ||
| codec.decode('http://example.com'), | ||
| Uri.parse('http://example.com'), | ||
| ); | ||
| expect( | ||
| codec.decode(' http://example.com '), | ||
| Uri.parse('http://example.com'), | ||
| ); | ||
| }); | ||
|
mark-dropbear marked this conversation as resolved.
|
||
|
|
||
| test('should throw FormatException for invalid URI', () { | ||
| expect( | ||
| () => codec.decode('http://example.com::'), | ||
| throwsA(isA<FormatException>()), | ||
| ); | ||
| }); | ||
| }); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.