Bug 1385172 - Replace nsEscapeHTML{,2}() with new nsAppendEscapedHTML() function. r=erahm.
The existing functions work with C strings but almost all the call sites use Mozilla strings. The replacement function has the following properties. - It works with Mozilla strings, which makes it much simpler and also improves the call sites. - It appends to the destination string because that's what a lot of the call sites need. For those that don't, we can just append to an empty string. - It is declared outside the |extern "C"| section because there is no need for it to be in that section. Note: there is no 16-bit variant of nsAppendEscapedHTML(). This is because there are only two places that need 16-bit variants, both rarely executed, and so converting to and from 8-bit is good enough. The patch also adds some testing of the new function, renaming TestEscapeURL.cpp as TestEscape.cpp in the process, because that file is now testing other kinds of escaping.
This commit is contained in:
@@ -251,7 +251,7 @@ WebExtensionPolicy::BackgroundPageHTML() const
|
||||
|
||||
for (auto& script : mBackgroundScripts.Value()) {
|
||||
nsCString escaped;
|
||||
escaped.Adopt(nsEscapeHTML(NS_ConvertUTF16toUTF8(script).get()));
|
||||
nsAppendEscapedHTML(NS_ConvertUTF16toUTF8(script), escaped);
|
||||
|
||||
result.AppendPrintf(kBackgroundPageHTMLScript, escaped.get());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user