File tree Expand file tree Collapse file tree 3 files changed +42
-4
lines changed Expand file tree Collapse file tree 3 files changed +42
-4
lines changed Original file line number Diff line number Diff line change @@ -776,10 +776,16 @@ bool url::set_port(const std::string_view input) {
776
776
if (cannot_have_credentials_or_port ()) {
777
777
return false ;
778
778
}
779
+
780
+ if (input.empty ()) {
781
+ port = std::nullopt;
782
+ return true ;
783
+ }
784
+
779
785
std::string trimmed (input);
780
786
helpers::remove_ascii_tab_or_newline (trimmed);
787
+
781
788
if (trimmed.empty ()) {
782
- port = std::nullopt;
783
789
return true ;
784
790
}
785
791
@@ -788,9 +794,15 @@ bool url::set_port(const std::string_view input) {
788
794
return false ;
789
795
}
790
796
797
+ // Find the first non-digit character to determine the length of digits
798
+ auto first_non_digit =
799
+ std::ranges::find_if_not (trimmed, ada::unicode::is_ascii_digit);
800
+ std::string_view digits_to_parse =
801
+ std::string_view (trimmed.data (), first_non_digit - trimmed.begin ());
802
+
791
803
// Revert changes if parse_port fails.
792
804
std::optional<uint16_t > previous_port = port;
793
- parse_port (trimmed );
805
+ parse_port (digits_to_parse );
794
806
if (is_valid) {
795
807
return true ;
796
808
}
Original file line number Diff line number Diff line change @@ -280,10 +280,16 @@ bool url_aggregator::set_port(const std::string_view input) {
280
280
if (cannot_have_credentials_or_port ()) {
281
281
return false ;
282
282
}
283
+
284
+ if (input.empty ()) {
285
+ clear_port ();
286
+ return true ;
287
+ }
288
+
283
289
std::string trimmed (input);
284
290
helpers::remove_ascii_tab_or_newline (trimmed);
291
+
285
292
if (trimmed.empty ()) {
286
- clear_port ();
287
293
return true ;
288
294
}
289
295
@@ -292,9 +298,15 @@ bool url_aggregator::set_port(const std::string_view input) {
292
298
return false ;
293
299
}
294
300
301
+ // Find the first non-digit character to determine the length of digits
302
+ auto first_non_digit =
303
+ std::ranges::find_if_not (trimmed, ada::unicode::is_ascii_digit);
304
+ std::string_view digits_to_parse =
305
+ std::string_view (trimmed.data (), first_non_digit - trimmed.begin ());
306
+
295
307
// Revert changes if parse_port fails.
296
308
uint32_t previous_port = components.port ;
297
- parse_port (trimmed );
309
+ parse_port (digits_to_parse );
298
310
if (is_valid) {
299
311
return true ;
300
312
}
Original file line number Diff line number Diff line change 98
98
"expected" : {
99
99
"port" : " 4"
100
100
}
101
+ },
102
+ {
103
+ "href" : " https://domain.com:3000" ,
104
+ "new_value" : " \n\t 80\n\t 80\n\t " ,
105
+ "expected" : {
106
+ "port" : " 8080"
107
+ }
108
+ },
109
+ {
110
+ "href" : " https://domain.com:3000" ,
111
+ "new_value" : " \n\n\t\t " ,
112
+ "expected" : {
113
+ "port" : " 3000"
114
+ }
101
115
}
102
116
],
103
117
"hash" : [
You can’t perform that action at this time.
0 commit comments