go-ruby-uri

Ruby's URI parse, build & normalize in pure Go โ€” MRI-compatible, no cgo.

pure Go ยท zero cgo MRI-compatible parse ยท build merge normalize components encode_www_form InvalidURIError MRI byte-exact 100% coverage 6 arches
Documentation GitHub
Documentation (MkDocs Material + mike) License: BSD-3-Clause Go 1.26.4+ Coverage 100%

go-ruby-uri is a pure-Go (no cgo) reimplementation of Ruby's URI library โ€” a parser, builder and normalizer that match reference Ruby's behaviour byte-for-byte. It splits a URI into scheme / userinfo / host / port / path / query / fragment with the per-scheme generic/HTTP/HTTPS/FTP/LDAP shapes Ruby uses, resolves relative references with merge / + per RFC 3986, normalizes scheme and host, and does encode_www_form and escape / unescape with Ruby's reserved-character tables โ€” raising the URI::InvalidURIError / URI::InvalidComponentError / URI::BadURIError taxonomy on the same inputs. It was extracted from rbgo's prelude/internals into a reusable standalone library: no dependency on the Ruby runtime, the dependency runs the other way. It is the URI backend for go-embedded-ruby, bound by rbgo as a native module just like go-ruby-regexp and go-ruby-erb โ€” differential-tested against MRI, 100% coverage, CI green across 6 arches and 3 OSes.

Parse & components ready

URI.parse(s) splitting scheme / userinfo / host / port / path / query / fragment, with the per-scheme generic/HTTP/HTTPS/FTP/LDAP shapes Ruby’s URI uses.

Build & merge ready

Constructing a URI from components and merge / + for relative-reference resolution, following RFC 3986 the way reference Ruby does.

Normalize ready

normalize lower-casing the scheme and host, collapsing default ports and dot-segments, matching MRI byte-for-byte.

encode_www_form & escaping ready

Form encoding/decoding and escape/unescape with Ruby’s reserved-character tables.

Error taxonomy ready

The URI::InvalidURIError / URI::InvalidComponentError / URI::BadURIError hierarchy, raised on the same inputs as reference Ruby.

Differential oracle & coverage ready

A wide URI corpus parsed, built and normalized both here and by the system ruby/uri, compared byte-for-byte; 100% coverage, gofmt + go vet clean, green across all six 64-bit Go arches and three OSes.

A faithful port of Ruby's URI parser, builder and normalizer in pure Go, cgo disabled, so it cross-compiles and embeds anywhere. It splits and rebuilds URIs across the generic and HTTP/HTTPS/FTP/LDAP shapes, resolves relative references with merge per RFC 3986, normalizes scheme and host, and does encode_www_form and escape / unescape with Ruby's reserved-character tables. Validated differentially against the system ruby binary โ€” parsed, built and normalized URIs compared against Ruby's uri. It is a standalone, reusable module extracted from rbgo's internals, and the URI backend for the sibling org github.com/go-embedded-ruby.