Comments (5)
The other option is to treat a parameter of test1
as having no value, and test2=
as having an empty value.
Then a URL of something?test1&test2=&test3=abc
would encode the difference and parsing back in could recreate it. (If there was no way to represent the difference in text, it can't be round-tripped, but this may be a way.)
I'll have to check what the WhatWG URL spec does, because I still hope to one day migrate Dart Uri
to that behavior.
If they don't distinguish the two cases, then Dart also won't.
If they do, then we may want to see if this is a breaking change worth making early, or is better to include it on a bigger update.
(Probably the latter, since we never noticed before.)
from sdk.
Labels: area-core-library
, type-bug
Summary: The Uri
class encodes empty and null query parameters identically, making it impossible to distinguish between them after parsing. This inconsistency with common conventions, like those used by Java Spring, can lead to unexpected behavior when interacting with other systems.
from sdk.
I think this is working as intended.
URIs are textual, they cannot represent "key with no value". Well, they could, but they don't.
As your example http://google.com?test2&test3=&test4=null
shows, that URI has the keys test2
, test3
and test4
.
Their values are the strings ""
, ""
and "null"
.
There is no support in a Uri
for having a key with no string value, so if the key is there, the value is at least the empty string.
from sdk.
That said, while this is intentional, it doesn't mean we can't change it. (It's harder, because it may break existing code).
So labeleing as enhancement request.
from sdk.
Thanks for your reply, Lasse. Your explanation made me realize an error in my reasoning (of course the String "null"
cannot always be taken to mean null
), but the main point is still valid:
To me it would seem reasonable if the following test passed, which currently it does not do.
import 'package:flutter_test/flutter_test.dart';
void main() {
test(
"URI encoding should not change value assigned to a parameter",
() {
final queryParameters = {"test": null};
final uri = Uri(queryParameters: queryParameters);
final uriString = uri.toString();
final parsedUri = Uri.parse(uriString);
final parsedParameters = parsedUri.queryParameters;
expect(queryParameters["test"], parsedParameters["test"]);
},
);
}
This could be reached by removing all key-value-pairs with a null
value when creating the query string. But yes, this might break existing code.
If you're happy to say the current behaviour is as intended, we can close this.
from sdk.
Related Issues (20)
- :memo: Data Assets Tracker
- Analyzer crash report: StackOverflowError at SubtypeHelper.isSubtypeOf HOT 2
- Quick fix doesn't create a correct recommendation when checking for exhaustiveness of a list pattern HOT 3
- Evaluate using pub workspace feature, dropping custom package config generator HOT 20
- [wildcards] Quick fix for dead late wildcard variable initializers
- Wrong dead code analysis on records with bool HOT 2
- Failures on [vm/shared] Add 'dart:concurrent' core library....[wildcards] `unnecessary_final` tests HOT 1
- Augmentation libraries: Conflict between `super` constructor and "The augmentation has an 'extends' clause, but an augmentation target already includes an 'extends' clause" and HOT 1
- [analyzer] Different completion results for constructors with and without named imports HOT 2
- 'Type inheritance' with augmentations does not support more than one step
- [vm/ffi] `KeepAlive` marker interface
- `dart analyze --options` does not exist (did with `dartanalyzer`) HOT 7
- Missing fuchsia targets in flutter hhh buildbot testing HOT 3
- [gardening] Iso-stress is found a crash HOT 1
- generic functions throw TypeError once generic information is lost HOT 10
- [dart2wasm] Follow-up tasks on source maps HOT 3
- `@doNotSubmit` isn't valid on member-fields HOT 5
- dart2wasm CRASH with demo app HOT 2
- Regex with unicode and curly braces does not match correctly HOT 2
- Send Pointer through SendPort without an error, which is different from the doc. HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sdk.