File tree Expand file tree Collapse file tree 3 files changed +14
-13
lines changed
Expand file tree Collapse file tree 3 files changed +14
-13
lines changed Original file line number Diff line number Diff line change @@ -73,6 +73,11 @@ namespace ada::helpers {
7373 */
7474 ada_really_inline void trim_c0_whitespace (std::string_view& input) noexcept ;
7575
76+ /* *
77+ * @see https://url.spec.whatwg.org/#potentially-strip-trailing-spaces-from-an-opaque-path
78+ */
79+ ada_really_inline void strip_trailing_spaces_from_opaque_path (ada::url& url) noexcept ;
80+
7681} // namespace ada::helpers
7782
7883#endif // ADA_HELPERS_H
Original file line number Diff line number Diff line change @@ -239,6 +239,13 @@ namespace ada::helpers {
239239 } while (true );
240240 }
241241 }
242+
243+ ada_really_inline void strip_trailing_spaces_from_opaque_path (ada::url& url) noexcept {
244+ if (!url.has_opaque_path ) return ;
245+ if (url.fragment .has_value ()) return ;
246+ if (url.query .has_value ()) return ;
247+ while (!url.path .empty () && url.path .back () == ' ' ) { url.path .resize (url.path .size ()-1 ); }
248+ }
242249} // namespace ada::helpers
243250
244251namespace ada {
Original file line number Diff line number Diff line change @@ -36,7 +36,7 @@ namespace ada {
3636 void url::set_hash (const std::string_view input) {
3737 if (input.empty ()) {
3838 fragment = std::nullopt ;
39- // TODO: Potentially strip trailing spaces from an opaque path with this.
39+ helpers::strip_trailing_spaces_from_opaque_path (* this );
4040 return ;
4141 }
4242
@@ -50,14 +50,7 @@ namespace ada {
5050 void url::set_search (const std::string_view input) {
5151 if (input.empty ()) {
5252 query = std::nullopt ;
53-
54- // Potentially strip trailing spaces from an opaque path
55- if (!has_opaque_path || fragment.has_value ()) return ;
56-
57- size_t non_whitespace_location = path.find_first_of (' ' );
58- if (non_whitespace_location != std::string_view::npos) {
59- path = path.substr (0 , non_whitespace_location);
60- }
53+ helpers::strip_trailing_spaces_from_opaque_path (*this );
6154 return ;
6255 }
6356
@@ -70,10 +63,6 @@ namespace ada {
7063 ada::character_sets::QUERY_PERCENT_ENCODE;
7164
7265 query = ada::unicode::percent_encode (std::string_view (new_value), query_percent_encode_set);
73-
74- // Set this’s query object’s list to the result of parsing input.
75- // @todo Implement this if/when we have URLSearchParams.
76- return ;
7766 }
7867
7968 bool url::set_pathname (const std::string_view input) {
You can’t perform that action at this time.
0 commit comments