Skip to content

Commit a551bba

Browse files
authored
fix: allow hyphens in URI segments (#29)
* fix: allow hyphens in URI segments The URI parser only accepted [a-zA-Z0-9.] in segments between colons, rejecting valid URNs containing hyphens (e.g. custom extension URIs like urn:example:scim:schemas:extension:my-custom-ext:1.0:User). Add "-" to the allowed character set per RFC 8141 Section 2, which defines the NID production as alphanum / "-" (ldh). * chore: add ci script to nix dev shell Adds a "ci" command to the nix dev shell that runs all four CI checks (test, lint, arrange, tidy) locally in one command.
1 parent 5c111b1 commit a551bba

4 files changed

Lines changed: 37 additions & 0 deletions

File tree

attrpath_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,9 @@ func ExampleParseAttrPath() {
77
// Output:
88
// urn:ietf:params:scim:schemas:core:2.0:User:name.familyName <nil>
99
}
10+
11+
func ExampleParseAttrPath_dash() {
12+
fmt.Println(ParseAttrPath([]byte("urn:example:scim:schemas:extension:my-custom-ext:1.0:User:name.familyName")))
13+
// Output:
14+
// urn:example:scim:schemas:extension:my-custom-ext:1.0:User:name.familyName <nil>
15+
}

flake.nix

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,26 @@
1212
devShells = forAllSystems (system:
1313
let
1414
pkgs = nixpkgs.legacyPackages.${system};
15+
ci = pkgs.writeShellScriptBin "ci" ''
16+
set -euo pipefail
17+
echo "--- test ---"
18+
go test -v ./...
19+
echo "--- lint ---"
20+
golangci-lint run -E misspell,godot,whitespace ./...
21+
echo "--- arrange ---"
22+
command -v goarrange >/dev/null || go install github.com/jdeflander/goarrange@v1.0.0
23+
test -z "$(goarrange run -r -d)"
24+
echo "--- tidy ---"
25+
go mod tidy
26+
git diff --quiet go.mod go.sum
27+
'';
1528
in
1629
{
1730
default = pkgs.mkShell {
1831
packages = [
1932
pkgs.go_1_26
2033
pkgs.golangci-lint
34+
ci
2135
];
2236
};
2337
}

internal/grammar/uri.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,15 @@ import (
77
"github.com/scim2/filter-parser/v2/internal/types"
88
)
99

10+
// URI parses a URN as defined in RFC 8141 Section 2.
11+
// https://datatracker.ietf.org/doc/html/rfc8141#section-2
12+
//
13+
// Each segment between colons may contain alphanumeric characters,
14+
// hyphens, and periods:
15+
// - NID allows alphanum and "-" (ldh production).
16+
// - NSS allows pchar (RFC 3986), which includes unreserved chars
17+
// (ALPHA / DIGIT / "-" / "." / "_" / "~"), but in practice SCIM
18+
// schema URNs only use alphanum, "-", and ".".
1019
func URI(p *ast.Parser) (*ast.Node, error) {
1120
return p.Expect(ast.Capture{
1221
Type: typ.URI,
@@ -16,6 +25,7 @@ func URI(p *ast.Parser) (*ast.Node, error) {
1625
parser.CheckRuneRange('a', 'z'),
1726
parser.CheckRuneRange('A', 'Z'),
1827
parser.CheckRuneRange('0', '9'),
28+
'-',
1929
'.',
2030
}),
2131
":",

internal/grammar/uri_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,10 @@ func ExampleURI() {
1111
// Output:
1212
// ["URI","urn:ietf:params:scim:schemas:core:2.0:User:"] <nil>
1313
}
14+
15+
func ExampleURI_dash() {
16+
p, _ := ast.New([]byte("urn:example:scim:schemas:extension:my-custom-ext:1.0:User:userName"))
17+
fmt.Println(URI(p))
18+
// Output:
19+
// ["URI","urn:example:scim:schemas:extension:my-custom-ext:1.0:User:"] <nil>
20+
}

0 commit comments

Comments
 (0)