Bug 1529190 - Make `execCommand("createLink")` and `execCommand("insertImage")` aware of URL including non-ASCII characters r=m_kato

`InsertTagCommand::DoCommandParams()` inserts given URL to `href` of `<a>` or
`src` of `<img>`.  However, it treats the given URL includes only ASCII
characters.  Therefore, we cannot insert URL including non-ASCII characters
with `execCommand("createLink")` nor `execCommand("insertImage")`.

This patch makes `nsHTMLDocument::ExecCommand()` set the param as `nsString`
and makes `InsertTagCommand::DoCommandParams()` retrieve it with `GetString()`.

Differential Revision: https://phabricator.services.mozilla.com/D20615

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Masayuki Nakano 2019-02-25 03:30:50 +00:00
Родитель 437a03b092
Коммит e4a493a90c
4 изменённых файлов: 21 добавлений и 17 удалений

Просмотреть файл

@ -2855,7 +2855,9 @@ bool nsHTMLDocument::ExecCommand(const nsAString& commandID, bool doShowUI,
RefPtr<nsCommandParams> params = new nsCommandParams();
if (isBool) {
rv = params->SetBool("state_attribute", boolVal);
} else if (cmdToDispatch.EqualsLiteral("cmd_fontFace")) {
} else if (cmdToDispatch.EqualsLiteral("cmd_fontFace") ||
cmdToDispatch.EqualsLiteral("cmd_insertImageNoUI") ||
cmdToDispatch.EqualsLiteral("cmd_insertLinkNoUI")) {
rv = params->SetString("state_attribute", value);
} else if (cmdToDispatch.EqualsLiteral("cmd_insertHTML") ||
cmdToDispatch.EqualsLiteral("cmd_insertText")) {

Просмотреть файл

@ -1404,19 +1404,11 @@ InsertTagCommand::DoCommandParams(const char* aCommandName,
return NS_ERROR_FAILURE;
}
// Don't use nsAutoCString here because nsCommandParams stores c-string member
// with nsCString*. Therefore, nsAutoCString always needs to copy the storage
// but nsCString may avoid it.
// TODO: This does not aware of URL which includes non-ASCII characters.
// A follow up bug will fix this.
nsCString asciiValue;
// do we have an href to use for creating link?
nsresult rv =
aParams->AsCommandParams()->GetCString(STATE_ATTRIBUTE, asciiValue);
if (NS_WARN_IF(NS_FAILED(rv))) {
return rv;
}
NS_ConvertASCIItoUTF16 value(asciiValue);
// Don't use nsAutoString here because nsCommandParams stores string member
// with nsString*. Therefore, nsAutoString always needs to copy the storage
// but nsString may avoid it.
nsString value;
nsresult rv = aParams->AsCommandParams()->GetString(STATE_ATTRIBUTE, value);
if (NS_WARN_IF(value.IsEmpty())) {
return NS_ERROR_INVALID_ARG;
}

Просмотреть файл

@ -239,5 +239,10 @@ var browserTests = [
[["createlink",""]],
"foo[bar]baz",
[false],
{"createlink":[false,false,"",false,false,""]}]
]
{"createlink":[false,false,"",false,false,""]}],
["foo[bar]baz",
[["createlink","http://www.google.com/\u65E5\u672C\u8A9E\u30D1\u30B9"]],
"foo<a href=\"http://www.google.com/\u65E5\u672C\u8A9E\u30D1\u30B9\">[bar]</a>baz",
[true],
{"createlink":[false,false,"",false,false,""]}],
]

Просмотреть файл

@ -349,5 +349,10 @@ var browserTests = [
[["insertimage","/img/lion.svg"]],
"<div>foo<p>bar<img src=\"/img/lion.svg\">{}baz</p></div>",
[true],
{"insertimage":[false,false,"",false,false,""]}]
{"insertimage":[false,false,"",false,false,""]}],
["foo[]bar",
[["insertimage","/\u65E5\u672C\u8A9E\u30D1\u30B9/lion.svg"]],
"foo<img src=\"/\u65E5\u672C\u8A9E\u30D1\u30B9/lion.svg\">{}bar",
[true],
{"insertimage":[false,false,"",false,false,""]}],
]