Catching more errors when parsing ICE server URLs.
Every malformed URL should now produce an error message in JS, rather than
silently failing and possibly printing a warning message to the console (and
possibly crashing).
Also added some unit tests, and made "ParseIceServers" public.
BUG=445002
Review URL: https://codereview.webrtc.org/1344143002
Cr-Commit-Position: refs/heads/master@{#10186}
diff --git a/webrtc/base/stringencode.cc b/webrtc/base/stringencode.cc
index 2930e57..01b41a6 100644
--- a/webrtc/base/stringencode.cc
+++ b/webrtc/base/stringencode.cc
@@ -556,7 +556,6 @@
size_t tokenize(const std::string& source, char delimiter,
std::vector<std::string>* fields) {
- RTC_DCHECK(fields);
fields->clear();
size_t last = 0;
for (size_t i = 0; i < source.length(); ++i) {
@@ -573,6 +572,21 @@
return fields->size();
}
+size_t tokenize_with_empty_tokens(const std::string& source,
+ char delimiter,
+ std::vector<std::string>* fields) {
+ fields->clear();
+ size_t last = 0;
+ for (size_t i = 0; i < source.length(); ++i) {
+ if (source[i] == delimiter) {
+ fields->push_back(source.substr(last, i - last));
+ last = i + 1;
+ }
+ }
+ fields->push_back(source.substr(last, source.length() - last));
+ return fields->size();
+}
+
size_t tokenize_append(const std::string& source, char delimiter,
std::vector<std::string>* fields) {
if (!fields) return 0;