Skip to content

Commit b46eeca

Browse files
committed
Move Protocol::URL::PATTERN to pattern.rb.
1 parent 8daf0ae commit b46eeca

File tree

4 files changed

+27
-14
lines changed

4 files changed

+27
-14
lines changed

lib/protocol/url.rb

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,14 @@
44
# Copyright, 2025, by Samuel Williams.
55

66
require_relative "url/version"
7+
require_relative "url/pattern"
78
require_relative "url/encoding"
89
require_relative "url/reference"
910
require_relative "url/relative"
1011
require_relative "url/absolute"
1112

1213
module Protocol
1314
module URL
14-
# RFC 3986 URI pattern with named capture groups.
15-
# Matches: [scheme:][//authority][path][?query][#fragment]
16-
# Rejects strings containing whitespace or control characters (matching standard URI behavior).
17-
PATTERN = %r{
18-
\A
19-
(?:(?<scheme>[a-z][a-z0-9+.-]*):)? # scheme (optional)
20-
(?://(?<authority>[^/?#\s]*))? # authority (optional, without //, no whitespace)
21-
(?<path>[^?#\s]*) # path (no whitespace)
22-
(?:\?(?<query>[^#\s]*))? # query (optional, no whitespace)
23-
(?:\#(?<fragment>[^\s]*))? # fragment (optional, no whitespace)
24-
\z
25-
}ix
26-
private_constant :PATTERN
27-
2815
# Coerce a value into an appropriate URL type (Absolute or Relative).
2916
#
3017
# @parameter value [String, Absolute, Relative, nil] The value to coerce.

lib/protocol/url/pattern.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# frozen_string_literal: true
2+
3+
# Released under the MIT License.
4+
# Copyright, 2025, by Samuel Williams.
5+
6+
module Protocol
7+
module URL
8+
# RFC 3986 URI pattern with named capture groups.
9+
# Matches: [scheme:][//authority][path][?query][#fragment]
10+
# Rejects strings containing whitespace or control characters (matching standard URI behavior).
11+
PATTERN = %r{
12+
\A
13+
(?:(?<scheme>[a-z][a-z0-9+.-]*):)? # scheme (optional)
14+
(?://(?<authority>[^/?#\s]*))? # authority (optional, without //, no whitespace)
15+
(?<path>[^?#\s]*) # path (no whitespace)
16+
(?:\?(?<query>[^#\s]*))? # query (optional, no whitespace)
17+
(?:\#(?<fragment>[^\s]*))? # fragment (optional, no whitespace)
18+
\z
19+
}ix
20+
end
21+
end

lib/protocol/url/reference.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# Released under the MIT License.
44
# Copyright, 2025, by Samuel Williams.
55

6+
require_relative "pattern"
67
require_relative "encoding"
78
require_relative "relative"
89

releases.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Releases
22

3+
## Unreleased
4+
5+
- Move `Protocol::URL::PATTERN` to `protocol/url/pattern.rb` so it can be shared more easily.
6+
37
## v0.1.0
48

59
- Initial implementation.

0 commit comments

Comments
 (0)