/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
// parse the base URI
mozilla::Tokenizer t(url);
mozilla::Tokenizer::Token token;
t.SkipWhites();
// We don't know if the url to check against starts with scheme // or a host name. Start recording here.
t.Record();
mozilla::Unused << t.Next(token);
// The ipv6 literals MUST be enclosed with [] in the preference. bool ipv6 = false; if (token.Equals(mozilla::Tokenizer::Token::Char('['))) {
nsDependentCSubstring ipv6BareLiteral; if (!t.ReadUntil(mozilla::Tokenizer::Token::Char(']'), ipv6BareLiteral)) { // Broken ipv6 literal returnfalse;
}
ipv6 = true;
} elseif (t.CheckChar(':') && t.CheckChar('/') && t.CheckChar('/')) { if (!matchScheme.Equals(token.Fragment())) { returnfalse;
} // Re-start recording the hostname from the point after scheme://.
t.Record();
}
while (t.Next(token)) { bool eof = token.Equals(mozilla::Tokenizer::Token::EndOfFile()); bool port = token.Equals(mozilla::Tokenizer::Token::Char(':'));
if (eof || port) { if (!ipv6) { // Match already performed above.
nsDependentCSubstring hostName;
t.Claim(hostName);
// An empty hostname means to accept everything for the schema if (!hostName.IsEmpty()) { /* host: bar.com foo.bar.com foobar.com foo.bar.com bar.com pref: bar.com bar.com bar.com .bar.com .bar.com result: accept accept reject accept reject
*/ if (!StringEndsWith(matchHost, hostName,
nsCaseInsensitiveUTF8StringComparator)) { returnfalse;
} if (matchHost.Length() > hostName.Length() &&
matchHost[matchHost.Length() - hostName.Length() - 1] != '.' &&
hostName[0] != '.') { returnfalse;
}
}
}
if (port) {
uint16_t portNumber; if (!t.ReadInteger(&portNumber)) { // Missing port number returnfalse;
} if (matchPort != portNumber) { returnfalse;
} if (!t.CheckEOF()) { returnfalse;
}
}
} elseif (ipv6) { // After an ipv6 literal there can only be EOF or :port. Everything else // must be treated as non-match/broken input. returnfalse;
}
}
// All negative checks has passed positively. returntrue;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.