angular icon indicating copy to clipboard operation
angular copied to clipboard

RouteParams issue

Open erikist opened this issue 9 years ago • 7 comments

I have observed that RouteParams get method is not actually always returning a string. I have an example project for reproduction available here: https://github.com/erikist/route-params-failure

erikist avatar Jul 19 '17 16:07 erikist

/cc @leonsenft

matanlurey avatar Jul 19 '17 17:07 matanlurey

There's a cast from Map<String, dynamic> to Map<String, String> here: https://github.com/dart-lang/angular/blob/master/angular/lib/src/router/rules/rules.dart#L95

The issue appears to stem from the fact the link DSL used to navigate is specified as List<dynamic>. For example, for the route @Route('/foo/:id', name: 'Foo'), the link can be written as ['Foo', {'id': 12}]. Notice 12 is an integer literal, not a string. I'm guessing this integer is then propagated all the way until the aforementioned cast.

Enforcing the DSL to be specified exclusively with strings would be cumbersome and a huge breaking change, so I suggest we just convert integer parameters to strings upon reading the navigation link.

leonsenft avatar Jul 19 '17 17:07 leonsenft

so I suggest we just convert integer parameters to strings upon reading the navigation link

Sounds like JS-like "magic" to me. I think it would be better to throw an error that only strings are allowed.
This would also cover other cases where not a literal but a reference is used that points to non-String and non-integer values.

zoechi avatar Jul 19 '17 19:07 zoechi

I've run into this issue internally, though at the time I thought it was me >.>

I think updating the link DSL would be a breaking change, right? If that takes too much time I think it would be much better for the framework to just call toString so that the API isn't actively lying to users.

jonahwilliams avatar Jul 19 '17 22:07 jonahwilliams

I concur! I am an idiot and more apt to trust the static analyzer more than myself. I'd also say a combover would also be okay of just changing the return type to dynamic so I don't lose faith in my tools. :-D

erikist avatar Jul 20 '17 00:07 erikist

Converting everything just to a string would work for me as well, the result for toString() of all kinds of references would also reveal what went wrong.
But now as Dart heading to strong mode, I'd prefer a fail fast strategy that points out errors instead of hiding them to hit me at unexpected times.

zoechi avatar Jul 20 '17 08:07 zoechi

Obsolete; this was the old router which is no longer supported.

leonsenft avatar Dec 06 '17 20:12 leonsenft