File: pattern.rb

package info (click to toggle)
ruby-protocol-url 0.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 144 kB
  • sloc: ruby: 504; makefile: 4
file content (21 lines) | stat: -rw-r--r-- 766 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2025, by Samuel Williams.

module Protocol
	module URL
		# RFC 3986 URI pattern with named capture groups.
		# Matches: [scheme:][//authority][path][?query][#fragment]
		# Rejects strings containing whitespace or control characters (matching standard URI behavior).
		PATTERN = %r{
			\A
			(?:(?<scheme>[a-z][a-z0-9+.-]*):)?      # scheme (optional)
			(?://(?<authority>[^/?#\s]*))?          # authority (optional, without //, no whitespace)
			(?<path>[^?#\s]*)                       # path (no whitespace)
			(?:\?(?<query>[^#\s]*))?                # query (optional, no whitespace)
			(?:\#(?<fragment>[^\s]*))?              # fragment (optional, no whitespace)
			\z
		}ix
	end
end