[Repo Assist] feat: add uri_string module bindings and tests#86
Draft
github-actions[bot] wants to merge 1 commit intomainfrom
Draft
[Repo Assist] feat: add uri_string module bindings and tests#86github-actions[bot] wants to merge 1 commit intomainfrom
github-actions[bot] wants to merge 1 commit intomainfrom
Conversation
Adds `Fable.Beam.UriString` — F# bindings for Erlang's `uri_string` stdlib module (available since OTP 21; quote/unquote require OTP 24+). ### Bindings (src/otp/UriString.fs) **Parsing**: - `parse` — parses a URI string into an opaque `UriMap` (returns Result) - Accessors: `scheme`, `userinfo`, `host`, `port`, `path`, `query`, `fragment` (each returns an option since URI components are optional) **Normalization / resolution**: - `normalize` — RFC 3986 normalization: lowercases scheme/host, removes default ports, resolves dot-segments, normalizes percent-encoding - `resolve` — resolves a URI reference against a base URI (RFC 3986) **Query string**: - `dissectQuery` — parses a query string into `(string * string) list` - `composeQuery` — builds a query string from `(string * string) list` **Percent encoding**: - `percentDecode` — decodes %XX sequences (returns Result; errors on invalid) - `quote` — percent-encodes data preserving only unreserved characters - `quoteWith` — like quote but with caller-specified safe characters - `unquote` — decodes percent-encoded data without erroring ### Tests (test/TestUriString.fs) — 20 tests - parse full URI with all 7 components - parse minimal URI (no port/query/fragment) - parse relative URI, path-only URI - normalize: scheme/host lowercasing, default port removal, dot-segment resolution - resolve: absolute ref, relative ref, full URI reference - dissectQuery / composeQuery: key-value parsing, empty cases, roundtrip - percentDecode: success, passthrough, malformed encoding error - quote, quoteWith with safe chars, unquote Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 This is an automated contribution from Repo Assist, an AI assistant.
What
Adds
Fable.Beam.UriString— F# bindings for Erlang'suri_stringstdlib module (OTP 21+). This was on the Repo Assist bindings backlog.Changes
src/otp/UriString.fs(new)Parsing — opaque
UriMaptype + accessors:parse(uri)Result<UriMap, string>scheme(m)string option(e.g."https")userinfo(m)string option(e.g."user:pass")host(m)string option(e.g."example.com")port(m)int optionpath(m)string optionquery(m)string option(without?)fragment(m)string option(without#)Normalization and resolution:
normalize(uri)Result<string, string>resolve(ref, base)Result<string, string>Query string handling:
dissectQuery(qs)(string * string) listcomposeQuery(pairs)stringPercent encoding / decoding:
percentDecode(uri)Result<string, string>quote(data)stringquoteWith(data, safe)quotebut with caller-specified safe chars →stringunquote(data)stringDesign notes
UriMapis[<Erase>] type UriMap = UriMap of obj— zero runtime cost; it's the raw Erlang map fromuri_string:parse/1maps:get(key, Map, undefined)so missing components correctly becomeNoneFile.fsandRe.fs) to handle Erlang's{error, atom(), term()}and convert toResult<_, string>quote/2SafeChars accepts an F# string (binary) which is valid in OTP 27+test/TestUriString.fs(new) — 20 testsNonedissectQuery/composeQuery: key-value parsing, empty cases, roundtrippercentDecode: success, passthrough, malformed encoding returnsErrorquote,quoteWithwith safe chars,unquoteOther
src/Fable.Beam.fsproj— addedUriString.fsafterRe.fstest/Fable.Beam.Test.fsproj— addedTestUriString.fsafterTestRe.fsREADME.md— addedFable.Beam.UriStringrow to the OTP modules tableTrade-offs
dissectQueryreturn type(string * string) listcannot represent query keys without values (where Erlang returnstrueas the value). Documented in the binding's doc comment. This edge case is rare in practice.quote/1,quote/2,unquote/1require OTP 24+. Documented; the CI uses OTP 27 so tests will pass.Validation
F# compilation verified with
dotnet build test/. Full BEAM validation (F# → Erlang → rebar3 compile → BEAM test runner) by CI.