Skip to content

[Feature #22634] Add URI::WHATWG_PARSER, a parser for the WHATWG URL Standard - #274

Open
jinroq wants to merge 72 commits into
ruby:masterfrom
jinroq:whatwg-parser
Open

jinroq wants to merge 72 commits into
ruby:masterfrom
jinroq:whatwg-parser

Conversation

@jinroq

@jinroq jinroq commented Nov 24, 2026

Copy link
Copy Markdown

This adds URI::WHATWG_Parser and its instance URI::WHATWG_PARSER, a parser that follows the WHATWG URL Standard. URI::DEFAULT_PARSER stays RFC 3986.

URI::WHATWG_PARSER.parse("HTTP://EXAMPLE.com:80/a/../b c")
#=> #<URI::HTTP http://example.com/b%20c>
URI::WHATWG_PARSER.parse("http://日本語.jp/").host
#=> "xn--wgv71a119e.jp"
URI.parser = URI::WHATWG_PARSER

Changes

  • lib/uri/whatwg_parser.rb: the basic URL parser, the host parser (domain to ASCII, IPv4 and IPv6), the serializer, and the interface that URI.parser= expects.
  • lib/uri/whatwg_parser/setters.rb: the setters of the URL Standard, and ==, normalize!, merge, route_to, route_from and to_s for the URIs that URI::WHATWG_PARSER builds, in a module prepended to URI::Generic. Other URIs are not affected.
  • lib/uri/whatwg_parser/idna.rb, punycode.rb, nfc.rb, nfc_tables.rb: UTS Refactor RFC3986 regexps to make more readable #46 ToASCII with the settings of the URL Standard, and Punycode (RFC 3492). The IDNA Mapping Table is derived from the Unicode data of Ruby (UTS Refactor RFC3986 regexps to make more readable #46 section 6), and NFC and NFKC use the tables of lib/unicode_normalize.
  • lib/uri/whatwg_parser/idna_data.rb (17KB): the Bidi_Class and Joining_Type values that Ruby has not, generated by rake idna:generate.
  • lib/uri/generic.rb: a protected set_query, and the require of the setters.
  • lib/uri/common.rb: URI::WHATWG_PARSER, and its documentation.

Tests

  • test/uri/test_whatwg_*.rb: tests that need no network.
  • test/wpt/: conformance tests run by rake test:wpt, which fetch the latest data:
    • web-platform-tests urltestdata.json (904 of 904 pass), toascii.json (87 of 87) and setters_tests.json (213 of 213 run; the host and href setters are not supported).
    • Unicode IdnaTestV2.txt 18.0.0 (all pass, except the cases that succeed with a character unknown to the running Ruby) and NormalizationTest.txt of the Unicode version of Ruby.
    • The tests of the harness itself run with rake test.
  • .github/workflows/wpt.yml runs rake test:wpt on push, on pull requests and weekly. On push and pull requests its failures do not fail the checks, since they can come from a change of WPT.

The tests pass on Ruby 2.5, 3.0, 3.4, 4.0 and 4.1-dev, and on JRuby.

jinroq and others added 30 commits November 18, 2026 17:35
Define URI::WHATWG_Parser and the URI::WHATWG_PARSER instance, loaded
with "uri" but not used by default: DEFAULT_PARSER stays RFC3986_PARSER.
It can be used directly or selected with URI.parser=.

The parser provides the full interface URI.parser= and URI::Generic
rely on (split, parse, join, regexp, convert_to_uri, and the obsolete
RFC2396-compatible extract, make_regexp, escape and unescape, which
delegate to RFC2396_PARSER as RFC3986_Parser does). split only handles
a simple absolute URL for now.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add `rake test:wpt`, which fetches url/resources/urltestdata.json from
web-platform-tests master (or the file or https URL in WPT_URLTESTDATA)
and runs each case against URI::WHATWG_PARSER. The tests live in
test/wpt/, outside test/uri/, and are not part of `rake test`, since
they need the network.

Known failures are listed with a reason in
test/wpt/urltestdata_exclusions.json. A listed case that passes, or one
that no longer exists in the data, makes the run fail.
`rake test:wpt:update_exclusions` regenerates the list, keeping known
reasons and marking new failures "unclassified".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Strip leading and trailing C0 control or space and remove all ASCII
tab or newline, as the first steps of the URL Standard's basic URL
parser do. The ends are found with index/rindex instead of an anchored
regexp, so long inner runs of spaces cannot cause quadratic
backtracking.

Input is converted to UTF-8 first. A string with an invalid byte
sequence, or one that cannot be converted, raises InvalidURIError.

Eight WPT urltestdata cases pass now and are removed from the
exclusions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Follow the URL Standard's scheme start state and scheme state: a scheme
is an ASCII alpha followed by ASCII alphanumerics, "+", "-" or ".", and
is ASCII-lowercased. Input without a scheme raises InvalidURIError, as
the no scheme state fails when there is no base URL.

Special schemes (ftp, file, http, https, ws, wss) are parsed as
hierarchical URLs. For other schemes, input starting with "//" has an
authority, input starting with "/" has a path, and anything else is an
opaque path, returned as the opaque component.

76 more WPT urltestdata cases pass and are removed from the exclusions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Follow the URL Standard's authority-related states:

* For special schemes, any run of "/" or "\" after the scheme is
  skipped (special authority slashes / ignore slashes states). Other
  schemes need exactly "//" to have an authority.
* The authority ends at "/", "?", "#", or for special schemes "\".
* The last "@" ends the userinfo; earlier ones become "%40". The first
  ":" separates the username from the password. Empty parts are
  omitted as the URL serializer does.
* The first ":" outside "[...]" separates the host from the port.
* A missing host is an error for special schemes, after a userinfo, or
  before a port. Other schemes may have an empty host.

file URLs keep an interim treatment until the file states are
implemented: exactly two leading slashes start a host, which may be
empty.

84 more WPT urltestdata cases pass and are removed from the exclusions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Follow the URL Standard's host parser:

* A host of a special URL is a domain. It is percent-decoded,
  UTF-8 decoded (invalid sequences become U+FFFD) and
  ASCII-lowercased, and fails if it contains a forbidden domain code
  point.
* A host of any other URL is an opaque host. It fails if it contains a
  forbidden host code point, and C0 controls and non-ASCII code points
  are percent-encoded.
* A host starting with "[" must end with "]".

Not implemented yet: IPv4 and IPv6 address parsing, and domain to
ASCII (UTS ruby#46) for non-ASCII domains, which are returned unchanged
for now.

117 more WPT urltestdata cases pass and are removed from the
exclusions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A domain that ends in a number is parsed as an IPv4 address, following
the URL Standard's ends in a number checker, IPv4 parser and IPv4
number parser:

* Each part is decimal, octal ("0" prefix) or hex ("0x"/"0X" prefix).
* Up to four parts; the last one fills the remaining bytes.
* Any part but the last over 255, or a last part too large for the
  remaining bytes, is an error.
* A single trailing "." is ignored.

The address is serialized in dotted decimal. Digits are checked with a
regexp before conversion, since String#to_i also accepts "_", and a
number with more significant digits than 2**32 - 1 has is rejected
without converting it. Opaque hosts are not parsed as IPv4.

38 more WPT urltestdata cases pass and are removed from the exclusions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A host in "[...]" is parsed with the URL Standard's IPv6 parser,
transcribed step by step so it can be compared with the standard: up
to eight 16-bit pieces of at most four hex digits, one "::"
compression, and an optional trailing IPv4 address of four decimal
parts without leading zeros. This applies to special and non-special
URLs alike.

The address is serialized with the IPv6 serializer: lowercase hex
without leading zeros, and the first longest run of two or more zero
pieces written as "::".

32 more WPT urltestdata cases pass and are removed from the exclusions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Follow the URL Standard's port state: a port is ASCII digits only, at
most 65535. An empty port, or one equal to the default port of a
special scheme, is omitted. The port is returned as a decimal string
without leading zeros. A port with more significant digits than 65535
has is rejected without converting it.

21 more WPT urltestdata cases pass and are removed from the exclusions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The fragment starts at the first "#" after the scheme, and the query at
the first "?" before it, since every earlier state of the URL
Standard's basic URL parser ends there. An empty query or fragment is
kept as "" rather than nil.

For an opaque path, a space right before "?" or "#" is written as
"%20", and the query stays inside opaque, as URI::RFC3986_Parser does,
since URI::Generic does not serialize the query of an opaque URI. The
WPT harness reads the query of an opaque URI from there.

50 more WPT urltestdata cases pass and are removed from the exclusions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Follow the URL Standard's path start state and path state:

* A special URL always has a path, "/" when empty. Its segments are
  separated by "/" or "\"; other URLs use "/" only, and have an empty
  path when nothing follows the authority.
* Single-dot segments ("." or "%2e") are removed and double-dot
  segments ("..", ".%2e", "%2e." or "%2e%2e", case-insensitively)
  remove the previous segment, never going above the root. At the end
  of the path, either one leaves a trailing "/".

A hostless path that would start with "//" gets the "/." prefix the
URL serializer writes, as URI::Generic does not know that rule; the WPT
harness drops it when reading pathname.

122 more WPT urltestdata cases pass and are removed from the
exclusions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Apply the URL Standard's percent-encode sets: the fragment set to the
fragment, the special-query or query set to the query, the path set to
each path segment before the dot-segment checks, the userinfo set to
the username and password separately, and the C0 control set to an
opaque path. Existing percent signs are left alone.

44 more WPT urltestdata cases pass and are removed from the exclusions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Parse into a URL record (scheme, username, password, host, port, path
segments or opaque path, query, fragment) as the URL Standard does, and
convert it to the components URI::RFC3986_Parser#split returns
afterwards. This keeps the serialization rules (userinfo, the "/."
prefix, the query inside opaque) in one place and lets a parsed URL be
used as a base for relative references.

No behavior change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
join now parses the base into a URL record and parses each further
argument with it as the base URL, following the URL Standard's no
scheme state, special relative or authority state, relative state and
relative slash state, instead of using URI::Generic#merge:

* Input without a scheme is relative to the base. A special scheme
  equal to the base's is too, unless two slashes follow it.
* An empty reference keeps the base path and query; "?..." keeps the
  path; a path keeps the base authority and resolves its segments
  against the shortened base path. The base fragment is never kept.
* A base with an opaque path only accepts a fragment.

split and parse still fail for input without a scheme, as there is no
base.

132 more WPT urltestdata cases pass and are removed from the
exclusions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
URI::Generic's constructor always sets the query through #query=, which
re-escapes it by RFC 3986 rules: it escapes "'" and "`", and rejects a
"%" not followed by two hex digits. The URL Standard keeps all of them,
so WHATWG_Parser now creates the URI object without the query and sets
it afterwards with a new protected URI::Generic#set_query, which
assigns it as is, like the other set_* methods.

5 more WPT urltestdata cases pass and are removed from the exclusions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
URI::WHATWG_Parser now creates scheme-specific objects only for http,
https, ws, wss and file, whose classes agree with the URL Standard.
Every other scheme gets URI::Generic: URI::FTP rewrites the path by
RFC 1738 rules ("ftp://h//a" became "ftp://h/%2Fa"), URI::MailTo
rejects opaque parts the URL Standard accepts, and URI::LDAP drops its
default port, which the URL Standard keeps for a non-special scheme.

URI::RFC3986_Parser is unchanged.

15 more WPT urltestdata cases pass and are removed from the exclusions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Replace the interim handling of file URLs with the URL Standard's file
state, file slash state and file host state:

* A file URL always has a host, empty unless two slashes (or
  backslashes) are followed by one. The host is a domain or IP address,
  without userinfo or port, and "localhost" becomes empty.
* A Windows drive letter in the first path segment is normalized to
  "X:", and shortening the path never removes it. A drive letter where
  the host would be starts the path instead.
* Relative to a file base, the base host and path are kept, and an
  absolute path keeps the base's drive letter unless it has its own.

44 more WPT urltestdata cases pass and are removed from the exclusions.
The remaining ones all need domain to ASCII (UTS ruby#46).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The workflow runs `rake test:wpt` with the latest stable Ruby against
urltestdata.json from WPT master. The weekly scheduled run fails, and
so notifies, when the URL Standard's tests change in a way the parser
or the exclusion list does not reflect yet. On push and pull requests
the result is reported without failing the checks, since a failure can
come from WPT rather than from the change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
URI::Generic#merge parsed the reference on its own before merging it by
RFC 3986 rules, but the URL Standard has no relative URLs without a
base, so `uri + "d"` raised InvalidURIError for every relative
reference when uri came from URI::WHATWG_PARSER. Such a URI now hands
the whole merge (and so URI#+ and URI#merge!) to its parser's join.

URIs from other parsers are merged as before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
All 32 cases still excluded have a domain that is non-ASCII after
percent-decoding, and need domain to ASCII (UTS ruby#46), which is not
implemented.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It was only needed for the interim handling of file URLs, which now
have their own states; it always equals special.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Describe how to use it, that relative references are resolved with
join or URI::Generic#merge rather than parsed alone, which schemes get
their own class, and that IDNA is not implemented.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Domain to ASCII (UTS ruby#46) converts each non-ASCII label to "xn--"
followed by its Punycode (RFC 3492), and decodes existing "xn--"
labels to validate them. Decoding returns nil for invalid input,
including code points beyond U+10FFFF, surrogates, and intermediate
values beyond 2**31 - 1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`rake idna:generate` fetches the IDNA Mapping Table and the Unicode
Character Database files of one Unicode version (UNICODE_VERSION,
defaulting to the version of the current data) and writes
lib/uri/whatwg_parser/idna_data.rb.

The data covers what domain to ASCII needs with the settings of the
URL Standard (Nontransitional Processing, UseSTD3ASCIIRules=false):
the mapping of mapped and ignored code points, the valid code points,
and, among the valid code points, General_Category=Mark,
Canonical_Combining_Class=Virama, Joining_Type and Bidi_Class.

The data is generated from Unicode 18.0.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Escapes make every code point visible, including combining marks and
look-alikes such as U+212A KELVIN SIGN.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
URI::WHATWG_Parser::IDNA.to_ascii is Unicode ToASCII (UTS ruby#46) with
the settings of the URL Standard: CheckHyphens=false, CheckBidi=true,
CheckJoiners=true, UseSTD3ASCIIRules=false,
Transitional_Processing=false, VerifyDnsLength=false and
IgnoreInvalidPunycode=false. It maps, normalizes to NFC with
String#unicode_normalize, decodes and validates "xn--" labels, checks
the validity criteria, the CONTEXTJ rules and the Bidi Rule, and
converts non-ASCII labels to Punycode. It returns nil on failure.

The Unicode data is loaded on first use, so `require "uri"` does not
pay for it. The parser does not call it yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
IdnaTestV2.txt is the conformance test of UTS ruby#46. It is fetched for
the Unicode version of the generated IDNA data, or read from
IDNA_TEST_V2. The toAsciiN column is checked, ignoring the status codes
of the checks that domain to ASCII turns off (V2, V3, U1, A4_1, A4_2
and X4_2). Cases holding a surrogate are skipped.

All 6394 checkable cases of Unicode 18.0.0 pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The host parser now runs the domain parser of the URL Standard with
beStrict false: an ASCII domain is lowercased, and any other domain
goes through URI::WHATWG_Parser::IDNA.to_ascii. The result fails when
it is empty or contains a forbidden domain code point, and a result
that ends in a number is parsed as IPv4. A percent-decoded domain that
is not valid UTF-8 fails, as its U+FFFD is disallowed.

Every case of WPT urltestdata.json passes now, so the exclusion list
is empty.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The encoding procedure of RFC 3492 scans the whole label once for each
distinct non-basic code point, so a host of 8000 distinct CJK
characters took 7 seconds to parse. The positions of each code point
are now visited in order, and the code points smaller than it between
two positions are counted with a Fenwick tree, which yields the same
deltas.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
jinroq and others added 30 commits November 18, 2026 18:34
The WPT test generates its cases in JavaScript rather than in a JSON
file, so its rules are ported to test/uri: with https and a non-special
scheme, U+0000, tab, LF, CR and U+001F at the start, in the middle and
at the end of the value of the protocol, username, password, hostname,
port, pathname, search and hash setters. The host setter and
searchParams cases are not ported, since URI has no equivalent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
userinfo= applies the username and password setters to the userinfo
split at its first ":", and removes the credentials for an empty value.
opaque= always raises InvalidComponentError, since the URL Standard has
no setter for an opaque path.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The setters percent-encoded the bytes of a value in its own encoding,
and raised Encoding::CompatibilityError for an ASCII-incompatible one.
A value is now converted to UTF-8 as the input of the parser is, and
one that cannot be converted raises InvalidComponentError.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Generic#== normalized the URIs, which made URLs that the URL Standard
tells apart equal, such as "foo://h" and "foo://h/", or opaque hosts
differing in case. Two URIs built by WHATWG_Parser are now equal when
their serializations are, and one is not equal to an RFC 3986 URI.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Generic#merge passed a relative URI bound to WHATWG_Parser, which
Generic#route_to returns, to WHATWG_Parser#join, which raised
InvalidURIError for its missing scheme. As for an RFC 3986 URI, an
absolute URI is now returned, and a relative reference raises
BadURIError.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Generic#route_to and #route_from converted a relative reference with
WHATWG_Parser, which raised InvalidURIError for its missing scheme. As
for an RFC 3986 URI, it now raises BadURIError.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The IDNA data and the NFC tables were loaded on first use with
require_relative, which before Ruby 4.0 is not safe in concurrent
non-main Ractors and could crash the process. On Ruby 3.x they are now
loaded with uri; elsewhere they are still loaded on first use.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The setters and join serialized a URI and parsed it again to get its
URL record. The components of a URI that WHATWG_Parser built are those
of a URL record, already serialized, so the record is now rebuilt from
them directly, which makes a setter about six times faster.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
port= converted all the digits of a value, while the parser stops
converting a number with more significant digits than the largest port.
Both now use the same conversion.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
host= scanned its value for the end of the host with a loop of its own.
It now cuts the value at the end of the authority and splits off the
port with split_host_and_port, as the parser does.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The parser and host= each turned an empty host or localhost of a file
URL into an empty host. Both now use file_host.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The normalization of RFC 3986 URIs made another URL of a WHATWG URI,
such as by adding a path to a non-special URL or by lowercasing an
opaque host. A URL is already normalized by the URL Standard, so
normalize! now leaves it unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Generic#merge, #route_to and #route_from0 checked for WHATWG_Parser
themselves. The module prepended to URI::Generic for WHATWG URIs now
overrides them, so URI::Generic keeps its methods as on master.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The module prepended to URI::Generic now covers equality,
normalization, merge and routes as well as the setters.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
It needs Ruby 2.7, while the gem supports Ruby 2.5.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
rake test left out all of test/wpt, so the tests of the harness, which
need no network, ran only in the WPT workflow, whose failures on push
and pull requests do not fail the checks.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Generic#to_s writes "//" for any postgres URI, which made a hostless
URL such as "postgres:/x" serialize as "postgres:///x", a URL with an
empty host. The URL serializer writes "//" only for a URL with a host.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
whatwg_url? returned nil for a URI that WHATWG_Parser did not build, so
== of a WHATWG URI and an RFC 3986 URI returned nil.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
join returned a single URI argument as it was, so a URI that another
parser built came back neither parsed nor normalized by the URL
Standard, with the methods of an RFC 3986 URI. It is now parsed as its
string would be.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The harness skipped them since URI's setters did not follow the URL
Standard, which they now do for WHATWG URIs. Each input is now also set
with host= on "https://x/x", as toascii.window.js does with the
hostname setter.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
route_to and route_from used the RFC 3986 algorithm, whose references
could resolve elsewhere by the URL Standard: an empty reference keeps
the query of the base, a path starting with "//" is an authority, a
non-special URL tells an empty path from "/", and only a fragment
resolves against an opaque path. The route is now the first of the
fragment, the query, the relative path, the path and the authority
with the path that resolves to the target, or the target itself.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
For each case with a base, the route from the base to the URL it parses
to must resolve back to that URL.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
As for an RFC 3986 URI, scheme= cannot change the class of the object,
which code such as open-uri checks. Parsing the URI again gives the
class of its new scheme. The test now checks the class exactly, since
URI::HTTPS is a URI::HTTP.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Decoding inserted each code point into the output, which takes time
proportional to the square of the length when each one goes to the
start, as for a label whose code points are in descending order. A
1.6MB URL with such a label took about 18 seconds to parse. The
insertions are now recorded, and more than a few are placed with a
Fenwick tree, going back from the last one. The URL now takes about 4
seconds, and labels of a usual length still go through an array.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
NFC used decomposition, composition and combining class tables
generated into idna_data.rb. It now builds them from the tables of
lib/unicode_normalize, which every Ruby has and which can be shared
between Ractors, so it has the Unicode version of the running Ruby. It
also gains NFKC, for deriving the IDNA mapping. The targets of
UnicodeNormalize::KOMPATIBLE_TABLE may still have canonical
decompositions, so they are decomposed again.

NormalizationTest.txt is now fetched for the Unicode version of the
running Ruby, and checks NFKC as well.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The IDNA mapping is about to be derived from the Unicode data of the
running Ruby, which does not know the code points added since its
Unicode version: a domain with one fails. The cases that succeed with
such a code point, in the source or in the decoded ASCII result, are
now not run, and their number is reported. Noncharacters are
unassigned in every version, so they do not count.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
idna_data.rb held the IDNA Mapping Table and the other Unicode data of
IDNA, 332KB. The status and the mapping of each code point are now
derived as UTS ruby#46 section 6 describes, from what Ruby has: NFKC and
case folding for NFKC_Casefold, and the character properties for the
base valid set. Marks and viramas come from Ruby as well, so
idna_data.rb now holds only the Bidi_Class and Joining_Type values that
the Bidi Rule and CONTEXTJ need, 17KB. Bidi_Class L, the class of most
valid code points, is no longer listed.

For every code point that the running Ruby knows, from Ruby 2.5
(Unicode 10.0) to 4.1 (Unicode 17.0), the derived status and mapping
are those of IdnaMappingTable.txt 18.0. A code point added since the
Unicode version of Ruby is unassigned, so disallowed.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A Regexp made with Regexp.new, unlike a literal, is not frozen, so a
non-main Ractor could not read IDNA::IDS_OPERATOR on Ruby 4.0, the
only version that both knows IDS_Unary_Operator and does not share
such a Regexp. Every constant of IDNA and NFC is now tested to be
shareable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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