Skip to content

Commit

Permalink
Add check for Edge browser setText issuing a location change url (#306)
Browse files Browse the repository at this point in the history
- add check for URL starting with "data:" which occurs when setText
  is called on Edge browser and use handler.handleTextSet()
- fixes: #248
  • Loading branch information
jjohnstn authored Oct 24, 2022
1 parent 0db3f77 commit 939c991
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2008, 2016 IBM Corporation and others.
* Copyright (c) 2008, 2022 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
Expand Down Expand Up @@ -255,11 +255,15 @@ public static LocationListener createLocationListener(final ILinkHandler handler
public void changing(LocationEvent event) {
String loc= event.location;

if ("about:blank".equals(loc)) { //$NON-NLS-1$
if ("about:blank".equals(loc) || loc.startsWith("data:")) { //$NON-NLS-1$ //$NON-NLS-2$
/*
* Using the Browser.setText API triggers a location change to "about:blank".
* XXX: remove this code once https://bugs.eclipse.org/bugs/show_bug.cgi?id=130314 is fixed
*/
// The check for "data:" is due to Edge browser issuing a location change with a URL using the data: protocol
// that contains the Base64 encoded version of the text whenever setText is called on the browser.
// See issue: https://github.com/eclipse-jdt/eclipse.jdt.ui/issues/248

//input set with setText
handler.handleTextSet();
return;
Expand Down Expand Up @@ -313,7 +317,7 @@ public void changing(LocationEvent event) {
}
if (nomatch) {
try {
if (handler.handleExternalLink(new URL(loc), event.display))
if (!(loc.startsWith("data:")) && handler.handleExternalLink(new URL(loc), event.display)) //$NON-NLS-1$
return;
event.doit= true;
} catch (MalformedURLException e) {
Expand Down

0 comments on commit 939c991

Please sign in to comment.