-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(UrlMatcher): Add param only type names #2289
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -917,7 +917,8 @@ function $UrlMatcherFactory() { | |
} | ||
|
||
function getType(config, urlType, location) { | ||
if (config.type && urlType) throw new Error("Param '"+id+"' has two type configurations."); | ||
if (config.type && urlType.name !== 'string') throw new Error("Param '"+id+"' has two type configurations."); | ||
if (config.type && urlType.name === 'string' && $types[config.type]) return $types[config.type]; | ||
if (urlType) return urlType; | ||
if (!config.type) return (location === "config" ? $types.any : $types.string); | ||
return config.type instanceof Type ? config.type : new Type(config.type); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. something like this:
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -520,6 +520,21 @@ describe("urlMatcherFactory", function () { | |
expect(m.format({ foo: 5, flag: true })).toBe("/5/1"); | ||
}); | ||
|
||
it("should match types named only in params", function () { | ||
var m = new UrlMatcher("/{foo}/{flag}", { | ||
params: { | ||
foo: { | ||
type: 'int' | ||
}, | ||
flag: { | ||
type: 'bool' | ||
} | ||
} | ||
}); | ||
expect(m.exec("/1138/1")).toEqual({ foo: 1138, flag: true }); | ||
expect(m.format({ foo: 5, flag: true })).toBe("/5/1"); | ||
}); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add a test for url-less parameters, like our discussion in issue #983 https://github.com/angular-ui/ui-router/blob/master/test/stateSpec.js#L1157-L1306 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I got so caught up on the type tests in the urlMatcher that I forgot tests for url-less params. My bad! |
||
it("should encode/decode dates", function () { | ||
var m = new UrlMatcher("/calendar/{date:date}"), | ||
result = m.exec("/calendar/2014-03-26"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
urlType
is optional, this code will break on url-less parameters. I liked the direction of your previous logic better, where it checks if config.type is a string.angular.isString
is a handy utility for checking if something is a string or not