0

Unescape URL ahead of editing.

This change permits any URLs with non latin1 characters to be
unescaped for direct editing in the omnibox.

This used to work before we migrated everything to GURL.

The change adds a new entry in JUnitTestGURLs that captures URL with
escaped non-latin1 characters.

Change-Id: Id756d9fd2fbe828270cf40fb0d34f8fa72a81d4e
Fixed: 969493
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4781503
Reviewed-by: Michael Thiessen <mthiesse@chromium.org>
Reviewed-by: Patrick Noland <pnoland@chromium.org>
Code-Coverage: findit-for-me@appspot.gserviceaccount.com <findit-for-me@appspot.gserviceaccount.com>
Commit-Queue: Tomasz Wiszkowski <ender@google.com>
Cr-Commit-Position: refs/heads/main@{#1184323}
This commit is contained in:
Tomasz Wiszkowski
2023-08-16 19:50:25 +00:00
committed by Chromium LUCI CQ
parent 5fdcc2122a
commit 346ae8a28e
3 changed files with 61 additions and 1 deletions
chrome/browser/ui/android/omnibox/java/src/org/chromium/chrome/browser/omnibox/suggestions/editurl
url/android/test/java/src/org/chromium/url

@ -34,6 +34,9 @@ import org.chromium.components.ukm.UkmRecorder;
import org.chromium.ui.base.Clipboard;
import org.chromium.ui.modelutil.PropertyModel;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.nio.charset.Charset;
import java.util.Arrays;
/**
@ -169,6 +172,13 @@ public class EditUrlSuggestionProcessor extends BaseSuggestionViewProcessor {
/** Invoked when user interacts with Edit action button. */
private void onEditLink(AutocompleteMatch suggestion) {
RecordUserAction.record("Omnibox.EditUrlSuggestion.Edit");
mUrlBarDelegate.setOmniboxEditingText(suggestion.getUrl().getSpec());
// Pass the decoded URL to the Omnibox to avoid %-encoded unicode characters.
var text = suggestion.getUrl().getSpec();
try {
text = URLDecoder.decode(text, Charset.defaultCharset().name());
} catch (UnsupportedEncodingException | IllegalArgumentException e) {
// text should not be modified here.
}
mUrlBarDelegate.setOmniboxEditingText(text);
}
}

@ -81,6 +81,10 @@ public final class EditUrlSuggestionProcessorUnitTest {
private static final int ACTION_EDIT = 2;
private static final GURL SEARCH_URL_1 = JUnitTestGURLs.getGURL(JUnitTestGURLs.SEARCH_URL);
private static final GURL SEARCH_URL_2 = JUnitTestGURLs.getGURL(JUnitTestGURLs.SEARCH_2_URL);
private static final GURL ESCAPED_PATH_URL =
JUnitTestGURLs.getGURL(JUnitTestGURLs.ESCAPED_PATH_URL_1);
private static final GURL INVALID_ESCAPED_PATH_URL =
JUnitTestGURLs.getGURL(JUnitTestGURLs.INVALID_ESCAPED_PATH_URL_1);
/** Used to simulate sad tabs. */
@Implements(SadTab.class)
@ -277,6 +281,42 @@ public final class EditUrlSuggestionProcessorUnitTest {
verifyNoMoreInteractions(mSuggestionHost, mUrlBarDelegate);
}
@Test
public void editButton_unescapesUrl() {
mMatch = new AutocompleteMatchBuilder(OmniboxSuggestionType.URL_WHAT_YOU_TYPED)
.setIsSearch(false)
.setDisplayText("test")
.setDescription(MATCH_TITLE)
.setUrl(ESCAPED_PATH_URL)
.build();
doReturn(ESCAPED_PATH_URL).when(mTab).getUrl();
mProcessor.populateModel(mMatch, mModel, 0);
mModel.get(BaseSuggestionViewProperties.ACTION_BUTTONS).get(ACTION_EDIT).callback.run();
// Expect the decoded content.
verify(mUrlBarDelegate).setOmniboxEditingText(JUnitTestGURLs.ESCAPED_PATH_URL_1_STRING);
verifyNoMoreInteractions(mSuggestionHost, mUrlBarDelegate);
}
@Test
public void editButton_fallsBackToMalformedUrlIfUnsecapeFails() {
mMatch = new AutocompleteMatchBuilder(OmniboxSuggestionType.URL_WHAT_YOU_TYPED)
.setIsSearch(false)
.setDisplayText("test")
.setDescription(MATCH_TITLE)
.setUrl(INVALID_ESCAPED_PATH_URL)
.build();
doReturn(INVALID_ESCAPED_PATH_URL).when(mTab).getUrl();
mProcessor.populateModel(mMatch, mModel, 0);
mModel.get(BaseSuggestionViewProperties.ACTION_BUTTONS).get(ACTION_EDIT).callback.run();
// Expect the original content.
verify(mUrlBarDelegate).setOmniboxEditingText(JUnitTestGURLs.INVALID_ESCAPED_PATH_URL_1);
verifyNoMoreInteractions(mSuggestionHost, mUrlBarDelegate);
}
@Test
public void shareButton_click() {
mProcessor.populateModel(mMatch, mModel, 0);

@ -60,6 +60,12 @@ public class JUnitTestGURLs {
public static final String GOOGLE_URL_PIG = "http://www.google.com/pig";
public static final String ABOUT_BLANK = "about:blank";
public static final String CHROME_ABOUT = "chrome://about";
// The following points to: https://pl.wikipedia.org/wiki/Gżegżółka
public static final String ESCAPED_PATH_URL_1 =
"https://pl.wikipedia.org/wiki/G%C5%BCeg%C5%BC%C3%B3%C5%82ka";
public static final String ESCAPED_PATH_URL_1_STRING =
"https://pl.wikipedia.org/wiki/Gżegżółka";
public static final String INVALID_ESCAPED_PATH_URL_1 = "https://pl.wikipedia.org/wiki/G%X";
// Map of URL string to GURL serialization.
/* package */ static final Map<String, String> sGURLMap;
@ -152,6 +158,10 @@ public class JUnitTestGURLs {
"68,1,true,0,5,0,-1,0,-1,0,-1,0,-1,6,5,0,-1,0,-1,false,false,about:blank");
map.put(CHROME_ABOUT,
"72,1,true,0,6,0,-1,0,-1,9,5,0,-1,14,1,0,-1,0,-1,false,false,chrome://about/");
map.put(ESCAPED_PATH_URL_1,
"118,1,true,0,5,0,-1,0,-1,8,16,0,-1,24,35,0,-1,0,-1,false,false,https://pl.wikipedia.org/wiki/G%C5%BCeg%C5%BC%C3%B3%C5%82ka");
map.put(INVALID_ESCAPED_PATH_URL_1,
"91,1,true,0,5,0,-1,0,-1,8,16,0,-1,24,9,0,-1,0,-1,false,false,https://pl.wikipedia.org/wiki/G%X");
sGURLMap = Collections.unmodifiableMap(map);
}