Skip to content

Commit 803274e

Browse files
committed
Use /#? as default delimiter
1 parent bc7349d commit 803274e

File tree

3 files changed

+103
-61
lines changed

3 files changed

+103
-61
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ import pathToRegexp "github.com/soongo/path-to-regexp"
5555
- **End** When `true` the regexp will match to the end of the string. (default: `true`)
5656
- **Start** When `true` the regexp will match from the beginning of the string. (default: `true`)
5757
- **Validate** When `false` the function can produce an invalid (unmatched) path. (default: `true`)
58-
- **Delimiter** The default delimiter for segments, e.g. `[^/]` for `:named` patterns. (default: `'/'`)
58+
- **Delimiter** The default delimiter for segments, e.g. `[^/#?]` for `:named` patterns. (default: `'/#?'`)
5959
- **EndsWith** Optional character, or list of characters, to treat as "end" characters.
6060
- **prefixes** List of characters to automatically consider prefixes when parsing. (default: `./`)
6161
- **Encode** How to encode uri. (default: `func (uri string, token interface{}) string { return uri }`)

path_to_regexp.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ func Parse(str string, options *Options) []interface{} {
287287
if options.Prefixes != nil {
288288
prefixes = *options.Prefixes
289289
}
290-
defaultPattern := "[^" + escapeString(anyString(options.Delimiter, "/")) + "]+?"
290+
defaultPattern := "[^" + escapeString(anyString(options.Delimiter, "/#?")) + "]+?"
291291
result, key, i, path := make([]interface{}, 0), 0, 0, ""
292292

293293
tryConsume := func(mode lexTokenMode) *string {
@@ -793,7 +793,7 @@ func tokensToRegExp(rawTokens []interface{}, tokens *[]Token, options *Options)
793793
if options.EndsWith != "" {
794794
endsWith = "[" + escapeString(options.EndsWith) + "]|$"
795795
}
796-
delimiter := "[" + escapeString(anyString(options.Delimiter, "/")) + "]"
796+
delimiter := "[" + escapeString(anyString(options.Delimiter, "/#?")) + "]"
797797
if start {
798798
route = "^"
799799
}
@@ -849,7 +849,7 @@ func tokensToRegExp(rawTokens []interface{}, tokens *[]Token, options *Options)
849849
}
850850

851851
s := "(?=" + endsWith + ")"
852-
if endsWith == "$" {
852+
if options.EndsWith == "" {
853853
s = "$"
854854
}
855855
route += s

0 commit comments

Comments
 (0)