addressable 2.9.1 → 2.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +244 -23
- data/README.md +36 -0
- data/lib/addressable/idna/native.rb +60 -11
- data/lib/addressable/idna/pure.rb +257 -103
- data/lib/addressable/template.rb +2288 -150
- data/lib/addressable/unicode_normalization.rb +58 -0
- data/lib/addressable/uri.rb +510 -152
- data/lib/addressable/version.rb +50 -2
- metadata +4 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cbf0d05ee25ac415d4d19ec6d4e485dd670dbdd88a881d2505146ba27f293754
|
|
4
|
+
data.tar.gz: 5f667e619f9e0d77167b1fc552c5da7e09d3a967e69bdd281b70721a599347bc
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e792cb5ccb419c82c10f2d46c3202abf87ecde86435291efccc5169c5855d68715c74809c12ba70d3fff9b516c5b7afee26b2b738c111a77f3460de79cd5a868
|
|
7
|
+
data.tar.gz: d37be1f26e4c09b8f63883534b94d26201e64339936f36999386aef47fbd7cd974fb5fa47a276c53e9bcdef1f57288183534356f0f3e500c5693cbb55b2bec34
|
data/CHANGELOG.md
CHANGED
|
@@ -1,70 +1,290 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## Addressable 2.10.0 <a name="v2.10.0">
|
|
4
|
+
|
|
5
|
+
### Breaking changes
|
|
6
|
+
|
|
7
|
+
- Ruby 3.2 and earlier and JRuby 9.4 are no longer supported, and loading Addressable on them gives a deprecation warning when deprecation warnings are turned on, as with `-W:deprecated` ([#706])
|
|
8
|
+
- `Addressable::URI::RULE_2A`, `RULE_2B_2C`, `RULE_2D` and `RULE_PREFIXED_PARENT`, deprecated in 2.9.1, are removed ([#669])
|
|
9
|
+
- `Addressable::URI` setters, `.new` and `#merge` raise for `false` instead of treating it as `nil` ([#667])
|
|
10
|
+
- `Addressable::URI#port=` and `.new` raise `InvalidURIError` for a port with a line break, such as `"8080\nx"` ([#663])
|
|
11
|
+
- `Addressable::URI` setters, `.new` and `.parse` raise `InvalidURIError` for a port above 65535 in a URI whose scheme has a default port, such as `http://example.com:70000/`, and for a port above the largest integer Ruby stores without a bignum, 2**62 - 1 on 64-bit platforms, in any URI ([#711])
|
|
12
|
+
- `Addressable::URI#origin=` raises `InvalidURIError` for a string with a path, query or fragment, which it dropped, and for one with userinfo that has a colon, from which it took the host: `https://user:pass@example.com` raises instead of setting the host to `user` ([#616], [GHSA-cwmp-x65r-27fv])
|
|
13
|
+
- `Addressable::URI.parse`, `.new` and the host setters raise `InvalidURIError` for brackets in a host that don't enclose an IPv6 address or IPvFuture literal, such as `http://[127.0.0.1]/` or `http://example[.]com/`, which they accepted ([GHSA-c7j3-jq7p-v3pr])
|
|
14
|
+
- `Addressable::URI#host=`, `#authority=`, `.new` and `.parse` raise `InvalidURIError` for a colon in a host outside the brackets of an IP literal, such as `example.com:8080` or `http://a:b:80/`, which they accepted ([GHSA-w5p3-7836-69vh])
|
|
15
|
+
- `Addressable::URI#user=`, `#password=`, `#userinfo=`, `#authority=`, `.new` and `.parse` raise `InvalidURIError` for `/`, `?`, `#`, `[`, `]` or `\` in the user or password, or `:` in the user, which they accepted: `uri.password = "#secret"` raises, and a password with these characters has to be pct-encoded first ([GHSA-qrq6-rcpx-pmm6])
|
|
16
|
+
- The strings a frozen `Addressable::URI` holds are frozen, so changing one, as in `uri.host << "x"`, raises `FrozenError` ([#668])
|
|
17
|
+
- `Addressable::Template#expand`, `#partial_expand`, `#match`, `#extract` and `#to_regexp` raise `InvalidTemplateError` for a template that doesn't match the RFC 6570 grammar, which expansion kept as text and matching read as literal text ([#660], [#693], [#697])
|
|
18
|
+
- `Addressable::Template` reads a prefix modifier outside 1 to 9999 or with a leading zero, such as `{var:0}`, `{var:05}` or `{var:10000}`, as malformed: `#expand`, `#partial_expand`, `#match`, `#extract` and `#to_regexp` raise `InvalidTemplateError` where they used to expand or match it, and `#variables` ignores the expression ([#618], [#693], [#697])
|
|
19
|
+
- `Addressable::Template` reads the operators RFC 6570 reserves, `=`, `,`, `!`, `@` and `|`, as malformed: `#expand`, `#partial_expand`, `#match`, `#extract` and `#to_regexp` raise `InvalidTemplateOperatorError` where expansion used to treat `{!var}` like `{var}`, and `#variables` ignores the expression ([#660], [#693], [#697])
|
|
20
|
+
- `Addressable::Template#expand` and `#partial_expand` raise `InvalidTemplateValueError` for a prefix modifier on a list or associative array ([#660])
|
|
21
|
+
- With the native backend, `Addressable::IDNA.punycode_encode` and `.punycode_decode` raise `IDN::Punycode::PunycodeError` for a string with a NUL, where they converted only the text before it: `punycode_encode("a\u0000b")` gave `"a-"` ([GHSA-mrrj-5mhw-rcf2])
|
|
22
|
+
- The pure-Ruby `Addressable::IDNA.to_ascii` raises `Addressable::IDNA::InvalidLabel` for a label that breaks the bidi rule of RFC 3454, such as `exampleא`, where it returned an A-label, as `idn-ruby` raises `IDN::Idna::IdnaError`; `Addressable::URI#normalize` keeps such a host pct-encoded: `http://example%D7%90.test/` gives itself, not `http://xn--example-c5i.test/` ([GHSA-fccw-gx6q-mh6c])
|
|
23
|
+
- `Addressable::Template#match` and `#extract` only read a pair in a `;`, `?` or `&` expression as the pair of a variable that isn't exploded when the name is one of the expression's variables, and only as many times as the expression has the name, and otherwise don't match: `{?q}` on `?admin=true` gives `nil`, not `{"q" => nil, "admin" => "true"}` ([GHSA-q5vw-6v74-fg2g])
|
|
24
|
+
- A processor's `match` pattern for a `;`, `?` or `&` variable that isn't exploded matches only the variable's value, as documented, so `Addressable::Template#match` and `#extract` no longer match a pattern that includes the name, such as `page=\d+` ([GHSA-q5vw-6v74-fg2g])
|
|
25
|
+
- The pure-Ruby `Addressable::IDNA.to_ascii` raises `Addressable::IDNA::InvalidLabel` for a label made only of characters nameprep maps to nothing, such as U+200B ZERO WIDTH SPACE in `"\u200B.example"`, where it returned an A-label, as `idn-ruby` raises `IDN::Idna::IdnaError` ([#703], [#714])
|
|
26
|
+
|
|
27
|
+
### Changed output
|
|
28
|
+
|
|
29
|
+
- `Addressable::URI#normalize`, `#==`, `#===`, `.normalized_encode`, the pure-Ruby `Addressable::IDNA.to_ascii` and `Addressable::Template#expand`, `#match` and `#extract` leave a run of more than 30 combining marks as it is instead of normalizing it, so they take linear time on any Ruby: `e` followed by 31 U+0301 keeps the `e` and all 31 marks, not `é` and 30 ([GHSA-v6hg-69pc-4f3f])
|
|
30
|
+
- `Addressable::URI.heuristic_parse("localhost:3000")` gives `http://localhost:3000`, not `localhost:3000` with a `localhost` scheme ([#691])
|
|
31
|
+
- `Addressable::URI#route_from` and `#route_to` give `./`, not `../`, for a route that would climb above the root ([#648])
|
|
32
|
+
- `Addressable::URI#query_values` reads `+` as a space in query names too, and for uppercase `HTTP` and `HTTPS`: `?a+b=c` gives `{"a b" => "c"}`, not `{"a+b" => "c"}` ([#607])
|
|
33
|
+
- `Addressable::URI#request_uri` percent-encodes control characters and spaces: `/a b?q=1` gives `/a%20b?q=1`, not `/a b?q=1` ([GHSA-qg8x-qm93-fw27])
|
|
34
|
+
- `Addressable::URI#normalize` and `.normalized_encode` keep U+037E GREEK QUESTION MARK pct-encoded instead of turning it into a `;` delimiter: `/a%CD%BEb` gives `/a%CD%BEb`, not `/a;b` ([#712])
|
|
35
|
+
- `Addressable::URI#normalize` keeps U+037E GREEK QUESTION MARK in a query: `?a=%CD%BE` gives `?a=%CD%BE`, not `?a=%3B` ([#712])
|
|
36
|
+
- `Addressable::Template#expand` treats an empty list or associative array as undefined and leaves out `nil` members: `{?list}` with `[]` gives nothing, not `?list=` ([#611])
|
|
37
|
+
- `Addressable::Template#expand` keeps pct-encoded triplets in reserved and fragment expansion: `{+id}` with `admin%2F` gives `admin%2F`, not `admin%252F` ([#656])
|
|
38
|
+
- `Addressable::Template#expand` gives `;a=`, not `;a`, for `{;a}` with `[""]` ([#689])
|
|
39
|
+
- `Addressable::Template#expand` gives `;a;a=y`, not `;a=;a=y`, for `{;a*}` with `["", "y"]` ([#688])
|
|
40
|
+
- `Addressable::Template#expand` pct-encodes non-ASCII literals: `café/{var}` gives `caf%C3%A9/value`, not `café/value` ([#676])
|
|
41
|
+
- `Addressable::Template#match` and `#extract` read a label value that contains `.` when the expression is set off by delimiters: `/f{.ext}` on `/f.tar.gz` gives `{"ext" => "tar.gz"}`, not `nil`, so code that tries several templates may pick a different one ([#692])
|
|
42
|
+
- `Addressable::Template#match` and `#extract` keep the empty members of an exploded value: `{/segments*}` on `/a/b/` gives `{"segments" => ["a", "b", ""]}`, not `{"segments" => ["a", "b"]}`, and on `/` gives `{"segments" => [""]}`, not `{"segments" => []}` ([#700])
|
|
43
|
+
- `Addressable::Template#match` and `#extract` give a variable that's repeated in an expression its first value: `{+v1,v2,v1}` on `a,b,c` gives `{"v1" => "a", "v2" => "b"}`, not `{"v1" => "", "v2" => "a"}` ([GHSA-xj9m-f88p-5j38])
|
|
44
|
+
- `Addressable::Template#match` and `#extract` give a value that more than one variable of a `/`, `.`, `+`, `#` or default expression could take to the first of them, leaving a later variable undefined when nothing is left for it: `{/a,b*}` on `/x/y/z` gives `{"a" => "x", "b" => ["y", "z"]}`, not `{"a" => "", "b" => ["x", "y", "z"]}` ([#715])
|
|
45
|
+
- The pure-Ruby `Addressable::IDNA.to_ascii` and `.to_unicode` keep trailing empty labels, as `idn-ruby` does: `bücher.example.` gives `xn--bcher-kva.example.`, not `xn--bcher-kva.example` ([#609])
|
|
46
|
+
- The pure-Ruby `Addressable::IDNA.to_ascii` treats U+3002 and U+FF61 as label separators, as `idn-ruby` does: `bücher。example` gives `xn--bcher-kva.example`, not `xn--bcherexample-dlb0569n` ([GHSA-x378-rg7m-2c49])
|
|
47
|
+
- `Addressable::IDNA.to_unicode` and `Addressable::URI#display_uri` leave an A-label as it is when it decodes to ASCII other than letters, digits and hyphens, or starts or ends with a hyphen: `xn--mn,chen-n2a` gives `xn--mn,chen-n2a`, not `mün,chen` ([#716])
|
|
48
|
+
|
|
49
|
+
### `Addressable::URI`
|
|
50
|
+
|
|
51
|
+
- Fix `#normalize`, `#normalized_host`, `#origin` and `#==` turning a pct-encoded or fullwidth colon in the host into the port delimiter: `http://example.com%3A8080/` normalizes to itself, not `http://example.com:8080/` ([GHSA-w5p3-7836-69vh])
|
|
52
|
+
- Fix `#normalize` and `#normalized_host` decoding a host twice: `http://127%252E0%252E0%252E1/` normalizes to `http://127%252e0%252e0%252e1/`, not `http://127.0.0.1/` ([GHSA-w5p3-7836-69vh])
|
|
53
|
+
- Lowercase the letters that decoding a host gives in `#normalize`, `#normalized_host`, `#origin` and `#==`: `http://%49NTERNAL.example/` normalizes to `http://internal.example/`, not `http://Internal.example/` ([GHSA-w5p3-7836-69vh])
|
|
54
|
+
- Fix `#normalize`, `#normalized_host` and `#origin` treating a dot before a pct-encoded line break in the host as a trailing dot: `http://localhost.%0A/` normalizes to itself, not `http://localhost./` ([GHSA-w5p3-7836-69vh])
|
|
55
|
+
- Fix `#route_from` and `#route_to` giving routes that don't resolve to the target ([#623], [#648])
|
|
56
|
+
- Fix `#userinfo=` splitting the user from the password at the last colon instead of the first ([#606])
|
|
57
|
+
- Fix `.normalized_encode` decoding pct-encoded delimiters, such as `%2F` in the path and `%26` in the query ([#589])
|
|
58
|
+
- Fix `#normalize` decoding `%3D` in a query name ([#589])
|
|
59
|
+
- Fix `#normalize` decoding a triplet in a query twice, such as `%252B` to `%2B` ([#589])
|
|
60
|
+
- Encode a colon in a relative path's first segment as `%3A` instead of `%2F` ([#675])
|
|
61
|
+
- Fix `#normalize` raising `InvalidURIError` for a colon left in a relative path's first segment ([#550], [#589])
|
|
62
|
+
- Keep an IPv6 host in brackets whole in `#origin=` ([#616])
|
|
63
|
+
- Leave a URI unchanged when a setter or `#defer_validation` raises ([#666])
|
|
64
|
+
- Fix `#normalized_host`, `#normalize`, `#display_uri` and `#freeze` raising `ArgumentError` for a host whose pct-encoded bytes aren't valid UTF-8; they stay pct-encoded: `http://a%a9b/` normalizes to `http://a%A9b/` ([#701])
|
|
65
|
+
- Fix `#normalized_host`, `#normalize`, `#display_uri` and `#===` raising the IDNA backend's error for a host it can't convert to a domain name; the host stays pct-encoded: with `idn-ruby`, `http://a%EF%BF%BD.example/` normalizes to itself instead of raising `IDN::Idna::IdnaError` ([#714])
|
|
66
|
+
- Fix `#display_uri` showing a different name for a host whose A-label has a pct-encoded character: `http://xn--mn%3Fchen-n2a.example/` displays as itself, not as `http://mn%ã3Fchen.example/` ([#716])
|
|
67
|
+
- Fix `#normalize` decoding a pct-encoded bracket in a registered name: `http://a%5Db.example/` gives `http://a%5Db.example/`, not `http://a]b.example/` ([GHSA-c7j3-jq7p-v3pr])
|
|
68
|
+
- Speed up `.unencode` on TruffleRuby for a long run of pct-encoded bytes that aren't ASCII ([#720])
|
|
69
|
+
|
|
70
|
+
### `Addressable::Template`
|
|
71
|
+
|
|
72
|
+
- Give equal templates the same `#hash` ([#604])
|
|
73
|
+
- Keep the separators of an expression with several variables in `#partial_expand` ([#670], [#690])
|
|
74
|
+
- Take values from any object with `each_pair` or `[]`, or from a block, in `#expand` and `#partial_expand` ([#512], [#133])
|
|
75
|
+
- Encode a `#` after the one that starts the fragment as `%23` ([#679])
|
|
76
|
+
- Transcode values to UTF-8, and handle text that isn't valid UTF-8 instead of raising `ArgumentError` ([#686])
|
|
77
|
+
- Allow variable names that start with a digit, such as `{42}` ([#684])
|
|
78
|
+
- Match non-ASCII text in a URI either as written or pct-encoded ([#680])
|
|
79
|
+
- Return copies from `#variables`, `#variable_defaults` and `MatchData#values` ([#619])
|
|
80
|
+
- Split an exploded value of the default, `+` and `#` operators into its members in `#match` and `#extract`: `{a*,b}` on `x,y,z` gives `{"a" => ["x", "y", "z"], "b" => nil}`, not `{"a" => ["x,y,"], "b" => "z"}` ([#700], [#715])
|
|
81
|
+
- Build the regexp for a template in linear time when it has non-ASCII literal text or a long run of expressions with no literal text between them ([GHSA-h78h-gj97-g737])
|
|
82
|
+
- Match a URI in linear time on Rubies that don't memoize regexps (MRI before 3.3, JRuby, TruffleRuby), except for some templates that combine an exploded variable, or several variables in one expression, with other expressions, and where a processor gives a variable its own pattern ([GHSA-grhv-8jgq-r74x], [GHSA-jrfq-gw62-2f3j], [GHSA-xfg6-27c4-wr4r], [GHSA-xj9m-f88p-5j38])
|
|
83
|
+
- Fix `#match` and `#extract` giving a `nil` key for an empty member of an exploded `?` or `&` variable: `{?a*,b,c*}` on `?&==` gives `{"a" => nil, "b" => nil, "c" => {"" => "="}}`, not `{"a" => nil, "b" => nil, nil => "", "c" => {nil => ""}}` ([GHSA-xfg6-27c4-wr4r])
|
|
84
|
+
- Keep everything after the first `=` of each pair in an exploded `;`, `?` or `&` value in `#match` and `#extract`: `{?a*}` on `?k=x=y` gives `{"a" => {"k" => "x=y"}}`, not `{"a" => {"k" => "x"}}` ([#687])
|
|
85
|
+
- Give a pair with the name of a variable that isn't exploded to that variable in `#match` and `#extract`, wherever it is in a `;`, `?` or `&` expression: `{?q,list*}` on `?page=1&q=cat` gives `{"q" => "cat", "list" => {"page" => "1"}}`, not `{"q" => nil, "page" => "1", "list" => {"q" => "cat"}}` ([GHSA-q5vw-6v74-fg2g])
|
|
86
|
+
|
|
87
|
+
### `Addressable::IDNA`
|
|
88
|
+
|
|
89
|
+
- Fix `.to_ascii` and `.to_unicode` in the native backend dropping the rest of a label after a NUL, so `http://internal.example%00x/` no longer normalizes to `http://internal.example/` ([GHSA-mrrj-5mhw-rcf2])
|
|
90
|
+
- Fix `.to_unicode` decoding a label to one with a label separator, such as `xn--victimexample-882l` to `victim。example` ([GHSA-x378-rg7m-2c49])
|
|
91
|
+
- Fix the pure-Ruby `.to_unicode` decoding a label that breaks the bidi rule of RFC 3454, such as `xn--example-c5i` to `exampleא`, which `idn-ruby` leaves unchanged ([GHSA-fccw-gx6q-mh6c])
|
|
92
|
+
- Remove the characters nameprep maps to nothing, such as a zero width joiner, in the pure-Ruby `.to_ascii`, as `idn-ruby` does ([#703])
|
|
93
|
+
- Fix the native `.to_ascii` and `.to_unicode` crashing the process for a string that isn't tagged as UTF-8 and has bytes that aren't valid UTF-8, such as `"caf\xE9.example".b`; they raise `ArgumentError`, as they do for a UTF-8 string ([#710])
|
|
94
|
+
|
|
95
|
+
[#133]: https://github.com/sporkmonger/addressable/pull/133
|
|
96
|
+
[#512]: https://github.com/sporkmonger/addressable/pull/512
|
|
97
|
+
[#550]: https://github.com/sporkmonger/addressable/pull/550
|
|
98
|
+
[#589]: https://github.com/sporkmonger/addressable/pull/589
|
|
99
|
+
[#604]: https://github.com/sporkmonger/addressable/pull/604
|
|
100
|
+
[#606]: https://github.com/sporkmonger/addressable/pull/606
|
|
101
|
+
[#607]: https://github.com/sporkmonger/addressable/pull/607
|
|
102
|
+
[#609]: https://github.com/sporkmonger/addressable/pull/609
|
|
103
|
+
[#611]: https://github.com/sporkmonger/addressable/pull/611
|
|
104
|
+
[#616]: https://github.com/sporkmonger/addressable/pull/616
|
|
105
|
+
[#618]: https://github.com/sporkmonger/addressable/pull/618
|
|
106
|
+
[#619]: https://github.com/sporkmonger/addressable/pull/619
|
|
107
|
+
[#623]: https://github.com/sporkmonger/addressable/pull/623
|
|
108
|
+
[#648]: https://github.com/sporkmonger/addressable/pull/648
|
|
109
|
+
[#656]: https://github.com/sporkmonger/addressable/pull/656
|
|
110
|
+
[#660]: https://github.com/sporkmonger/addressable/pull/660
|
|
111
|
+
[#663]: https://github.com/sporkmonger/addressable/pull/663
|
|
112
|
+
[#666]: https://github.com/sporkmonger/addressable/pull/666
|
|
113
|
+
[#667]: https://github.com/sporkmonger/addressable/pull/667
|
|
114
|
+
[#668]: https://github.com/sporkmonger/addressable/pull/668
|
|
115
|
+
[#669]: https://github.com/sporkmonger/addressable/pull/669
|
|
116
|
+
[#670]: https://github.com/sporkmonger/addressable/pull/670
|
|
117
|
+
[#675]: https://github.com/sporkmonger/addressable/pull/675
|
|
118
|
+
[#676]: https://github.com/sporkmonger/addressable/pull/676
|
|
119
|
+
[#679]: https://github.com/sporkmonger/addressable/pull/679
|
|
120
|
+
[#680]: https://github.com/sporkmonger/addressable/pull/680
|
|
121
|
+
[#684]: https://github.com/sporkmonger/addressable/pull/684
|
|
122
|
+
[#686]: https://github.com/sporkmonger/addressable/pull/686
|
|
123
|
+
[#687]: https://github.com/sporkmonger/addressable/pull/687
|
|
124
|
+
[#688]: https://github.com/sporkmonger/addressable/pull/688
|
|
125
|
+
[#689]: https://github.com/sporkmonger/addressable/pull/689
|
|
126
|
+
[#690]: https://github.com/sporkmonger/addressable/pull/690
|
|
127
|
+
[#691]: https://github.com/sporkmonger/addressable/pull/691
|
|
128
|
+
[#692]: https://github.com/sporkmonger/addressable/pull/692
|
|
129
|
+
[#693]: https://github.com/sporkmonger/addressable/pull/693
|
|
130
|
+
[#697]: https://github.com/sporkmonger/addressable/pull/697
|
|
131
|
+
[#700]: https://github.com/sporkmonger/addressable/pull/700
|
|
132
|
+
[#701]: https://github.com/sporkmonger/addressable/pull/701
|
|
133
|
+
[#703]: https://github.com/sporkmonger/addressable/pull/703
|
|
134
|
+
[#706]: https://github.com/sporkmonger/addressable/pull/706
|
|
135
|
+
[#710]: https://github.com/sporkmonger/addressable/pull/710
|
|
136
|
+
[#711]: https://github.com/sporkmonger/addressable/pull/711
|
|
137
|
+
[#712]: https://github.com/sporkmonger/addressable/pull/712
|
|
138
|
+
[#714]: https://github.com/sporkmonger/addressable/pull/714
|
|
139
|
+
[#715]: https://github.com/sporkmonger/addressable/pull/715
|
|
140
|
+
[#716]: https://github.com/sporkmonger/addressable/pull/716
|
|
141
|
+
[#720]: https://github.com/sporkmonger/addressable/pull/720
|
|
142
|
+
[GHSA-c7j3-jq7p-v3pr]: https://github.com/sporkmonger/addressable/security/advisories/GHSA-c7j3-jq7p-v3pr
|
|
143
|
+
[GHSA-cwmp-x65r-27fv]: https://github.com/sporkmonger/addressable/security/advisories/GHSA-cwmp-x65r-27fv
|
|
144
|
+
[GHSA-fccw-gx6q-mh6c]: https://github.com/sporkmonger/addressable/security/advisories/GHSA-fccw-gx6q-mh6c
|
|
145
|
+
[GHSA-grhv-8jgq-r74x]: https://github.com/sporkmonger/addressable/security/advisories/GHSA-grhv-8jgq-r74x
|
|
146
|
+
[GHSA-h78h-gj97-g737]: https://github.com/sporkmonger/addressable/security/advisories/GHSA-h78h-gj97-g737
|
|
147
|
+
[GHSA-jrfq-gw62-2f3j]: https://github.com/sporkmonger/addressable/security/advisories/GHSA-jrfq-gw62-2f3j
|
|
148
|
+
[GHSA-mrrj-5mhw-rcf2]: https://github.com/sporkmonger/addressable/security/advisories/GHSA-mrrj-5mhw-rcf2
|
|
149
|
+
[GHSA-q5vw-6v74-fg2g]: https://github.com/sporkmonger/addressable/security/advisories/GHSA-q5vw-6v74-fg2g
|
|
150
|
+
[GHSA-qg8x-qm93-fw27]: https://github.com/sporkmonger/addressable/security/advisories/GHSA-qg8x-qm93-fw27
|
|
151
|
+
[GHSA-qrq6-rcpx-pmm6]: https://github.com/sporkmonger/addressable/security/advisories/GHSA-qrq6-rcpx-pmm6
|
|
152
|
+
[GHSA-v6hg-69pc-4f3f]: https://github.com/sporkmonger/addressable/security/advisories/GHSA-v6hg-69pc-4f3f
|
|
153
|
+
[GHSA-w5p3-7836-69vh]: https://github.com/sporkmonger/addressable/security/advisories/GHSA-w5p3-7836-69vh
|
|
154
|
+
[GHSA-x378-rg7m-2c49]: https://github.com/sporkmonger/addressable/security/advisories/GHSA-x378-rg7m-2c49
|
|
155
|
+
[GHSA-xfg6-27c4-wr4r]: https://github.com/sporkmonger/addressable/security/advisories/GHSA-xfg6-27c4-wr4r
|
|
156
|
+
[GHSA-xj9m-f88p-5j38]: https://github.com/sporkmonger/addressable/security/advisories/GHSA-xj9m-f88p-5j38
|
|
157
|
+
|
|
158
|
+
## Addressable 2.9.2 <a name="v2.9.2">
|
|
159
|
+
|
|
160
|
+
### `Addressable::URI`
|
|
161
|
+
|
|
162
|
+
- fixes `Addressable::URI` returning stale values after a component was
|
|
163
|
+
changed: e.g. after `host=`, `#site`, `#normalized_site`,
|
|
164
|
+
`#normalized_authority` and `#normalize` could still use the old host, and
|
|
165
|
+
after `scheme=`, `#normalized_port` could keep a port that's the new
|
|
166
|
+
scheme's default ([#613])
|
|
167
|
+
- fixes `Addressable::URI#normalized_query` reusing the result of an earlier
|
|
168
|
+
call with different flags: e.g. after `normalized_query(:sorted)`,
|
|
169
|
+
`normalized_query` and `#normalize` gave a sorted query, and after
|
|
170
|
+
`normalized_query`, `normalized_query(:sorted)` gave an unsorted one ([#608])
|
|
171
|
+
- fixes `Addressable::URI#clone` sharing component strings with the original:
|
|
172
|
+
e.g. appending to the clone's `#host` also changed the original's host, but
|
|
173
|
+
not its cached normalized values; `#dup` already made a separate copy ([#617])
|
|
174
|
+
- fixes the "instance variable @validation_deferred not initialized" warning
|
|
175
|
+
that 2.9.1 gave for every new `Addressable::URI` on Ruby before 3.0 with
|
|
176
|
+
warnings enabled, and a "shadowing outer local variable" warning from
|
|
177
|
+
`Addressable::Template` on Ruby 2.4 and 2.5 ([#637])
|
|
178
|
+
|
|
179
|
+
### `Addressable::Template`
|
|
180
|
+
|
|
181
|
+
- fixes `Addressable::Template#expand` and `#partial_expand` changing the
|
|
182
|
+
arrays given as values: e.g. `[1, :a]` became `["1", "a"]`; a frozen array
|
|
183
|
+
raised `FrozenError`, and an object that responds to `to_ary`
|
|
184
|
+
raised `TypeError` ([#605])
|
|
185
|
+
|
|
186
|
+
### `Addressable::IDNA`
|
|
187
|
+
|
|
188
|
+
- fixes the pure-Ruby `Addressable::IDNA.to_unicode` raising `ZeroDivisionError`
|
|
189
|
+
on some malformed labels, e.g. `xn--rp3=`, which also made
|
|
190
|
+
`Addressable::URI#display_uri` raise, because the Punycode decoder
|
|
191
|
+
treated punctuation as digits; such labels are now returned unchanged ([#614])
|
|
192
|
+
- speeds up the pure-Ruby `Addressable::IDNA.to_unicode`, which became up to
|
|
193
|
+
25 times slower in 2.9.1 on long labels with many non-ASCII characters;
|
|
194
|
+
Punycode encoding no longer takes quadratic time ([#645])
|
|
195
|
+
- fixes the "character class has duplicated range" warnings that 2.9.1 gave
|
|
196
|
+
when `Addressable::IDNA` was loaded with warnings enabled ([#636])
|
|
197
|
+
|
|
198
|
+
[#605]: https://github.com/sporkmonger/addressable/pull/605
|
|
199
|
+
[#608]: https://github.com/sporkmonger/addressable/pull/608
|
|
200
|
+
[#613]: https://github.com/sporkmonger/addressable/pull/613
|
|
201
|
+
[#614]: https://github.com/sporkmonger/addressable/pull/614
|
|
202
|
+
[#617]: https://github.com/sporkmonger/addressable/pull/617
|
|
203
|
+
[#636]: https://github.com/sporkmonger/addressable/pull/636
|
|
204
|
+
[#637]: https://github.com/sporkmonger/addressable/pull/637
|
|
205
|
+
[#645]: https://github.com/sporkmonger/addressable/pull/645
|
|
206
|
+
|
|
3
207
|
## Addressable 2.9.1 <a name="v2.9.1">
|
|
208
|
+
|
|
209
|
+
### `Addressable::URI`
|
|
210
|
+
|
|
4
211
|
- fixes denial of service in `Addressable::URI.normalize_path`, which took
|
|
5
212
|
quadratic time on paths with many dot segments; `URI#normalize`, `#join`,
|
|
6
|
-
`#==` and `#===` were affected (GHSA-qq38-m9mg-xjj5)
|
|
213
|
+
`#==` and `#===` were affected ([GHSA-qq38-m9mg-xjj5])
|
|
7
214
|
- fixes `Addressable::URI.normalize_path` keeping segments that a `..` should
|
|
8
215
|
have removed after a `..` above the root, e.g.
|
|
9
216
|
`/../../public/x/../../secret` normalized to `/public/x/secret` instead of
|
|
10
|
-
`/secret` (GHSA-8gmh-2hhj-2hv9)
|
|
217
|
+
`/secret` ([GHSA-8gmh-2hhj-2hv9])
|
|
11
218
|
- fixes `Addressable::URI.normalize_path` treating a raw line feed as a
|
|
12
219
|
segment boundary, e.g. joining `..\n/secret` onto `/public/` gave
|
|
13
220
|
`/\n/secret`
|
|
14
221
|
- deprecates `Addressable::URI::RULE_2A`, `RULE_2B_2C`, `RULE_2D` and
|
|
15
222
|
`RULE_PREFIXED_PARENT`, which are no longer used; they will be removed in
|
|
16
223
|
2.10.0
|
|
224
|
+
- fixes `Addressable::URI#route_from` and `#route_to` raising
|
|
225
|
+
`InvalidURIError` when the route's first segment contains a colon
|
|
226
|
+
(e.g. `/a:b` from `/a`); the route is now `./a:b` ([#625])
|
|
227
|
+
- fixes `Addressable::URI#display_uri` raising `InvalidURIError` for URIs
|
|
228
|
+
without a host, such as `abc` or `mailto:user@example.com`; relative URIs
|
|
229
|
+
are also no longer displayed with an empty authority (e.g. `/path/to` was
|
|
230
|
+
displayed as `///path/to`) ([#610])
|
|
231
|
+
- fixes `Addressable::URI#origin=` raising `InvalidURIError` for an origin
|
|
232
|
+
with an empty port (e.g. `http://example.com:`), which is the same as no
|
|
233
|
+
port ([#627])
|
|
234
|
+
|
|
235
|
+
### `Addressable::Template`
|
|
236
|
+
|
|
17
237
|
- fixes denial of service in `Addressable::Template#match` and `#extract`,
|
|
18
238
|
which still backtracked exponentially in 2.9.0 for exploded `/`, `.`, `;`,
|
|
19
239
|
`?` and `&` expressions (e.g. `{/path*}`) on regex engines without match
|
|
20
240
|
memoization, such as JRuby, TruffleRuby and MRI before 3.2; match results
|
|
21
|
-
are unchanged (GHSA-j82w-28jv-3pmj)
|
|
241
|
+
are unchanged ([GHSA-j82w-28jv-3pmj])
|
|
22
242
|
- fixes denial of service in `Addressable::Template#match` and `#extract`,
|
|
23
243
|
which backtracked polynomially or exponentially on the same regex engines
|
|
24
244
|
for expressions with several variables (e.g. `{/owner,repo,ref}`, or
|
|
25
245
|
`{+a,b,c}` with many variables), for `;` expressions, and for adjacent
|
|
26
246
|
expressions (e.g. `{+a}{+b}{+c}` or `{+a}{b}`); match results are unchanged
|
|
27
|
-
(GHSA-9f42-57jx-vpp3)
|
|
247
|
+
([GHSA-9f42-57jx-vpp3])
|
|
28
248
|
- fixes denial of service in `Addressable::Template#match` and `#extract`,
|
|
29
249
|
which backtracked polynomially for expressions with several exploded
|
|
30
250
|
variables (e.g. `{+a*,b*}`), including on MRI 3.2; match results are
|
|
31
|
-
unchanged (GHSA-4w5q-wg7v-w6gp)
|
|
251
|
+
unchanged ([GHSA-4w5q-wg7v-w6gp])
|
|
252
|
+
- fixes `Addressable::Template#match` and `#extract` raising
|
|
253
|
+
`Addressable::URI::InvalidURIError` for a string that isn't a valid URI;
|
|
254
|
+
they now return `nil`, as for any other URI that doesn't match ([#621])
|
|
255
|
+
|
|
256
|
+
### `Addressable::IDNA`
|
|
257
|
+
|
|
32
258
|
- fixes `Addressable::IDNA.to_unicode` in the pure-Ruby backend decoding
|
|
33
259
|
Punycode labels that aren't valid A-labels: labels that decode to only
|
|
34
260
|
ASCII characters (e.g. `xn--google-` decoded to `google`) and labels that
|
|
35
261
|
don't convert back to themselves; such a label is now returned unchanged,
|
|
36
262
|
as with libidn, so `Addressable::URI#display_uri` no longer shows a host
|
|
37
|
-
that differs from `#normalized_host` (GHSA-9crm-g4mf-wc5j)
|
|
263
|
+
that differs from `#normalized_host` ([GHSA-9crm-g4mf-wc5j])
|
|
38
264
|
- fixes `Addressable::IDNA.to_unicode` decoding Punycode labels with
|
|
39
265
|
characters that change how a host displays without being visible
|
|
40
266
|
themselves, such as bidi overrides and isolates (e.g. U+202E and U+2066),
|
|
41
267
|
zero width characters and control characters; such a label is now
|
|
42
268
|
returned unchanged, so `Addressable::URI#display_uri` no longer shows
|
|
43
269
|
them. The pure-Ruby backend also no longer decodes labels with other
|
|
44
|
-
characters that nameprep prohibits, as with libidn (GHSA-539f-xcgw-2gjg)
|
|
45
|
-
- fixes `Addressable::URI#route_from` and `#route_to` raising
|
|
46
|
-
`InvalidURIError` when the route's first segment contains a colon
|
|
47
|
-
(e.g. `/a:b` from `/a`); the route is now `./a:b` ([#625])
|
|
270
|
+
characters that nameprep prohibits, as with libidn ([GHSA-539f-xcgw-2gjg])
|
|
48
271
|
- fixes `Addressable::IDNA.to_unicode` raising in the pure-Ruby backend for
|
|
49
272
|
Punycode labels that are too long, overflow the decoder, or decode past
|
|
50
273
|
U+10FFFF; the label is now returned unchanged, as with libidn, so
|
|
51
274
|
`Addressable::URI#display_uri` no longer raises for such hosts ([#620])
|
|
52
|
-
- fixes `Addressable::URI#display_uri` raising `InvalidURIError` for URIs
|
|
53
|
-
without a host, such as `abc` or `mailto:user@example.com`; relative URIs
|
|
54
|
-
are also no longer displayed with an empty authority (e.g. `/path/to` was
|
|
55
|
-
displayed as `///path/to`) ([#610])
|
|
56
|
-
- fixes `Addressable::Template#match` and `#extract` raising
|
|
57
|
-
`Addressable::URI::InvalidURIError` for a string that isn't a valid URI;
|
|
58
|
-
they now return `nil`, as for any other URI that doesn't match ([#621])
|
|
59
|
-
- fixes `Addressable::URI#origin=` raising `InvalidURIError` for an origin
|
|
60
|
-
with an empty port (e.g. `http://example.com:`), which is the same as no
|
|
61
|
-
port ([#627])
|
|
62
275
|
|
|
63
276
|
[#610]: https://github.com/sporkmonger/addressable/pull/610
|
|
64
277
|
[#620]: https://github.com/sporkmonger/addressable/pull/620
|
|
65
278
|
[#621]: https://github.com/sporkmonger/addressable/pull/621
|
|
66
279
|
[#625]: https://github.com/sporkmonger/addressable/pull/625
|
|
67
280
|
[#627]: https://github.com/sporkmonger/addressable/pull/627
|
|
281
|
+
[GHSA-4w5q-wg7v-w6gp]: https://github.com/sporkmonger/addressable/security/advisories/GHSA-4w5q-wg7v-w6gp
|
|
282
|
+
[GHSA-8gmh-2hhj-2hv9]: https://github.com/sporkmonger/addressable/security/advisories/GHSA-8gmh-2hhj-2hv9
|
|
283
|
+
[GHSA-9crm-g4mf-wc5j]: https://github.com/sporkmonger/addressable/security/advisories/GHSA-9crm-g4mf-wc5j
|
|
284
|
+
[GHSA-9f42-57jx-vpp3]: https://github.com/sporkmonger/addressable/security/advisories/GHSA-9f42-57jx-vpp3
|
|
285
|
+
[GHSA-qq38-m9mg-xjj5]: https://github.com/sporkmonger/addressable/security/advisories/GHSA-qq38-m9mg-xjj5
|
|
286
|
+
[GHSA-j82w-28jv-3pmj]: https://github.com/sporkmonger/addressable/security/advisories/GHSA-j82w-28jv-3pmj
|
|
287
|
+
[GHSA-539f-xcgw-2gjg]: https://github.com/sporkmonger/addressable/security/advisories/GHSA-539f-xcgw-2gjg
|
|
68
288
|
|
|
69
289
|
## Addressable 2.9.0 <a name="v2.9.0">
|
|
70
290
|
- fixes ReDoS vulnerability in Addressable::Template#match (fixes incomplete
|
|
@@ -78,16 +298,16 @@
|
|
|
78
298
|
- No need for bundler as development dependency ([#571], [5fc1d93](https://github.com/sporkmonger/addressable/commit/5fc1d93))
|
|
79
299
|
- idna/pure: stop building the useless `COMPOSITION_TABLE` (removes the `Addressable::IDNA::COMPOSITION_TABLE` constant) ([#564])
|
|
80
300
|
|
|
301
|
+
[#564]: https://github.com/sporkmonger/addressable/pull/564
|
|
81
302
|
[#569]: https://github.com/sporkmonger/addressable/pull/569
|
|
82
303
|
[#571]: https://github.com/sporkmonger/addressable/pull/571
|
|
83
|
-
[#564]: https://github.com/sporkmonger/addressable/pull/564
|
|
84
304
|
|
|
85
305
|
## Addressable 2.8.8 <a name="v2.8.8">
|
|
86
306
|
- Replace the `unicode.data` blob by a ruby constant ([#561])
|
|
87
307
|
- Allow `public_suffix` 7 ([#558])
|
|
88
308
|
|
|
89
|
-
[#561]: https://github.com/sporkmonger/addressable/pull/561
|
|
90
309
|
[#558]: https://github.com/sporkmonger/addressable/pull/558
|
|
310
|
+
[#561]: https://github.com/sporkmonger/addressable/pull/561
|
|
91
311
|
|
|
92
312
|
## Addressable 2.8.7 <a name="v2.8.7">
|
|
93
313
|
- Allow `public_suffix` 6 ([#535])
|
|
@@ -116,8 +336,8 @@
|
|
|
116
336
|
## Addressable 2.8.3 <a name="v2.8.3">
|
|
117
337
|
- Fix template expand level 2 hash support for non-string objects ([#499], [#498])
|
|
118
338
|
|
|
119
|
-
[#499]: https://github.com/sporkmonger/addressable/pull/499
|
|
120
339
|
[#498]: https://github.com/sporkmonger/addressable/pull/498
|
|
340
|
+
[#499]: https://github.com/sporkmonger/addressable/pull/499
|
|
121
341
|
|
|
122
342
|
## Addressable 2.8.2 <a name="v2.8.2">
|
|
123
343
|
- Improve cache hits and JIT friendliness ([#486](https://github.com/sporkmonger/addressable/pull/486))
|
|
@@ -126,6 +346,7 @@
|
|
|
126
346
|
- Resolve normalization differences between `IDNA::Native` and `IDNA::Pure` ([#408](https://github.com/sporkmonger/addressable/issues/408), [#492])
|
|
127
347
|
- Remove redundant colon in `Addressable::URI::CharacterClasses::AUTHORITY` regex ([#438](https://github.com/sporkmonger/addressable/pull/438)) (accidentally reverted by [#449] merge but [added back](https://github.com/sporkmonger/addressable/pull/492#discussion_r1105125280) in [#492])
|
|
128
348
|
|
|
349
|
+
[#449]: https://github.com/sporkmonger/addressable/pull/449
|
|
129
350
|
[#492]: https://github.com/sporkmonger/addressable/pull/492
|
|
130
351
|
|
|
131
352
|
## Addressable 2.8.1 <a name="v2.8.1">
|
data/README.md
CHANGED
|
@@ -84,6 +84,7 @@ template.extract(uri)
|
|
|
84
84
|
# "segments" => ["a", "b", "c"],
|
|
85
85
|
# "one" => "1",
|
|
86
86
|
# "two" => "2",
|
|
87
|
+
# "bogus" => nil,
|
|
87
88
|
# "fragment" => "foo"
|
|
88
89
|
# }
|
|
89
90
|
```
|
|
@@ -103,6 +104,41 @@ $ brew install libidn # OS X
|
|
|
103
104
|
$ gem install idn-ruby
|
|
104
105
|
```
|
|
105
106
|
|
|
107
|
+
## Supported Ruby versions
|
|
108
|
+
|
|
109
|
+
Addressable supports Ruby 3.3 or later, JRuby 10 or later, and TruffleRuby
|
|
110
|
+
releases compatible with Ruby 3.3 or later. Ruby 3.2 and earlier, and
|
|
111
|
+
JRuby 9.4, are no longer supported. Addressable still installs on them for
|
|
112
|
+
now, and a future version of Addressable will require Ruby 3.3. On these
|
|
113
|
+
environments, Addressable gives a deprecation warning when it's loaded. Like
|
|
114
|
+
Ruby's own deprecation warnings, it's only shown when they're turned on,
|
|
115
|
+
with `-w`, `-W:deprecated` or `Warning[:deprecated] = true` (only `-w` on
|
|
116
|
+
Ruby 2.6 and earlier).
|
|
117
|
+
|
|
118
|
+
### Untrusted input on Ruby 3.3, JRuby and TruffleRuby
|
|
119
|
+
|
|
120
|
+
Security reports for issues that only affect Ruby 3.3, JRuby or
|
|
121
|
+
TruffleRuby aren't accepted (see [SECURITY.md](SECURITY.md)). If you run
|
|
122
|
+
Addressable on one of them and pass it untrusted input, limit how long it
|
|
123
|
+
can spend on that input.
|
|
124
|
+
|
|
125
|
+
On Ruby 3.3 and JRuby, wrap calls that handle untrusted input in a timeout:
|
|
126
|
+
|
|
127
|
+
```ruby
|
|
128
|
+
require "timeout"
|
|
129
|
+
|
|
130
|
+
uri = Timeout.timeout(1) { Addressable::URI.parse(untrusted_input) }
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
`Timeout.timeout` can interrupt the block at any point, so keep the block
|
|
134
|
+
small. On Ruby 3.3, `Regexp.timeout` is an alternative, but it applies to
|
|
135
|
+
every regexp in the process.
|
|
136
|
+
|
|
137
|
+
On TruffleRuby, `Timeout.timeout` can't always interrupt work that's
|
|
138
|
+
already in progress. Limit the length of untrusted input instead, for
|
|
139
|
+
example by rejecting a URI longer than a few thousand characters before
|
|
140
|
+
passing it to Addressable. A length limit works on Ruby 3.3 and JRuby too.
|
|
141
|
+
|
|
106
142
|
## Semantic Versioning
|
|
107
143
|
|
|
108
144
|
This project uses [Semantic Versioning](https://semver.org/). You can (and should) specify your
|
|
@@ -22,12 +22,21 @@ require "idn"
|
|
|
22
22
|
module Addressable
|
|
23
23
|
module IDNA
|
|
24
24
|
def self.punycode_encode(value)
|
|
25
|
-
IDN::Punycode.encode(value.to_s)
|
|
25
|
+
IDN::Punycode.encode(without_nul(value.to_s))
|
|
26
26
|
end
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
def self.punycode_decode(value)
|
|
29
|
+
IDN::Punycode.decode(without_nul(value.to_s))
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# libidn reads a NUL as the end of the string and would drop the rest.
|
|
33
|
+
def self.without_nul(value)
|
|
34
|
+
if value.include?("\0")
|
|
35
|
+
raise IDN::Punycode::PunycodeError, "Invalid input: NUL"
|
|
36
|
+
end
|
|
37
|
+
value
|
|
38
|
+
end
|
|
39
|
+
private_class_method :without_nul
|
|
31
40
|
|
|
32
41
|
class << self
|
|
33
42
|
# @deprecated Use {String#unicode_normalize(:nfkc)} instead
|
|
@@ -39,9 +48,28 @@ module Addressable
|
|
|
39
48
|
deprecate :unicode_normalize_kc, "String#unicode_normalize(:nfkc)", 2023, 4
|
|
40
49
|
end
|
|
41
50
|
|
|
51
|
+
# The value's bytes, read as UTF-8, as the pure-Ruby implementation
|
|
52
|
+
# reads them. libidn reads them that way too, but idn-ruby crashes when
|
|
53
|
+
# it rejects bytes from a string that isn't tagged as UTF-8, so those
|
|
54
|
+
# raise ArgumentError when the value is split, before it's called. A
|
|
55
|
+
# string in an encoding that isn't ASCII-compatible, such as UTF-16,
|
|
56
|
+
# is left as it is, and still raises when it's split.
|
|
57
|
+
def self.utf8(value)
|
|
58
|
+
value = value.to_s
|
|
59
|
+
return value unless value.encoding.ascii_compatible?
|
|
60
|
+
value.dup.force_encoding(Encoding::UTF_8)
|
|
61
|
+
end
|
|
62
|
+
private_class_method :utf8
|
|
63
|
+
|
|
64
|
+
# The errors .to_ascii raises for a domain name it can't convert.
|
|
65
|
+
CONVERSION_ERRORS = [IDN::IDNError].freeze
|
|
66
|
+
|
|
42
67
|
def self.to_ascii(value)
|
|
43
|
-
value.
|
|
44
|
-
if segment.
|
|
68
|
+
utf8(value).split('.', -1).map do |segment|
|
|
69
|
+
if segment.include?("\0")
|
|
70
|
+
# libidn would read the NUL as the end of the label.
|
|
71
|
+
segment
|
|
72
|
+
elsif segment.size > 0 && segment.size < 64
|
|
45
73
|
IDN::Idna.toASCII(segment, IDN::Idna::ALLOW_UNASSIGNED)
|
|
46
74
|
elsif segment.size >= 64
|
|
47
75
|
segment
|
|
@@ -55,14 +83,35 @@ module Addressable
|
|
|
55
83
|
# themselves: controls, format characters such as bidi overrides and
|
|
56
84
|
# isolates, and default ignorable code points. libidn rejects most of
|
|
57
85
|
# them, but not those added to Unicode after the version it checks
|
|
58
|
-
# against, such as U+2066 to U+2069.
|
|
59
|
-
|
|
86
|
+
# against, such as U+2066 to U+2069. Format characters that are also
|
|
87
|
+
# default ignorable are left out of the second set, since Ruby warns about
|
|
88
|
+
# a duplicated range in a character class.
|
|
89
|
+
DISPLAY_CHANGING = /[\p{Cc}\p{Cf}[\p{Default_Ignorable_Code_Point}&&\P{Cf}]]/
|
|
90
|
+
|
|
91
|
+
# The label separators of IDNA2003 (Section 3.1 of RFC 3490, since
|
|
92
|
+
# obsoleted by RFC 5890 and RFC 5891). A label that decodes to one of
|
|
93
|
+
# them would display as two labels.
|
|
94
|
+
LABEL_SEPARATORS = /[.\u3002\uFF0E\uFF61]/
|
|
95
|
+
|
|
96
|
+
# A host name has only ASCII letters, digits and hyphens, and doesn't
|
|
97
|
+
# start or end with a hyphen. RFC 3987 says to check an IRI's host names
|
|
98
|
+
# with these rules (STD3, section 4.1 of RFC 3490), so a label that
|
|
99
|
+
# decodes to anything else isn't displayed.
|
|
100
|
+
NOT_STD3 = /[\x00-\x2C\x2E\x2F\x3A-\x40\x5B-\x60\x7B-\x7F]|\A-|-\z/
|
|
60
101
|
|
|
61
102
|
def self.to_unicode(value)
|
|
62
|
-
value.
|
|
63
|
-
if segment.
|
|
103
|
+
utf8(value).split('.', -1).map do |segment|
|
|
104
|
+
if segment.include?("\0")
|
|
105
|
+
# libidn would read the NUL as the end of the label.
|
|
106
|
+
segment
|
|
107
|
+
elsif segment.size > 0 && segment.size < 64
|
|
64
108
|
decoded = IDN::Idna.toUnicode(segment, IDN::Idna::ALLOW_UNASSIGNED)
|
|
65
|
-
decoded =~ DISPLAY_CHANGING
|
|
109
|
+
if decoded =~ DISPLAY_CHANGING || decoded =~ LABEL_SEPARATORS ||
|
|
110
|
+
decoded =~ NOT_STD3
|
|
111
|
+
segment
|
|
112
|
+
else
|
|
113
|
+
decoded
|
|
114
|
+
end
|
|
66
115
|
elsif segment.size >= 64
|
|
67
116
|
segment
|
|
68
117
|
else
|