Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,33 @@ public static CharSequence escapeQuotesAndBackslash(final CharSequence input)
return s;
}

/**
* Removes the surrounding single quotes from a string after trimming
* leading and trailing whitespace.
*
* <p>Examples:</p>
* <pre>
* unquoteSingleQuoted(" 'url' ") -> "url"
* unquoteSingleQuoted("'url'") -> "url"
* unquoteSingleQuoted("''") -> ""
* </pre>
*
* @param s the single-quoted string
* @return the contents between the outer single quotes
*/
public static String unquoteSingleQuoted(String s)
{
if (s != null)
{
var trimmed = s.trim();
if (trimmed.length() > 1 && trimmed.startsWith("'") && trimmed.endsWith("'"))
{
s = trimmed.substring(1, trimmed.length() - 1);
}
}
return s;
}

/**
* Write a reference to a javascript file to the response object
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import org.apache.wicket.request.cycle.RequestCycle;
import org.apache.wicket.request.flow.RedirectToUrlException;

import static org.apache.wicket.core.util.string.JavaScriptUtils.escapeQuotesAndBackslash;

/**
* <p>
* A simple anchor link (&lt;a href="http://url"&gt;) pointing to any URL. Usually this is used for
Expand Down Expand Up @@ -189,7 +191,7 @@ public void renderHead(IHeaderResponse response)
{
if (popupSettings != null)
{
popupSettings.setTarget(url);
popupSettings.setTarget("'" + url + "'");
response.render(OnEventHeaderItem.forComponent(this, "click",
popupSettings.getPopupJavaScript()));
return;
Expand All @@ -208,7 +210,7 @@ public void renderHead(IHeaderResponse response)
response.render(OnEventHeaderItem.forComponent(this, "click",
"var win = this.ownerDocument.defaultView || this.ownerDocument.parentWindow; " //
+ "if (win == window) { window.location.href='" //
+ JavaScriptUtils.escapeQuotes(url) //
+ escapeQuotesAndBackslash(url) //
+ "'; } ;return false"));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import org.apache.wicket.model.IModel;
import org.apache.wicket.request.mapper.parameter.PageParameters;

import static org.apache.wicket.core.util.string.JavaScriptUtils.escapeQuotesAndBackslash;

/**
* Implementation of a hyperlink component. A link can be used with an anchor (&lt;a href...)
* element or any element that supports the onclick javascript event handler (such as buttons, td
Expand Down Expand Up @@ -414,7 +416,7 @@ public void renderHead(IHeaderResponse response)
// next check for popup settings
if (popupSettings != null)
{
popupSettings.setTarget(url.toString());
popupSettings.setTarget("'" + url.toString() + "'");
response.render(OnEventHeaderItem.forComponent(this, "click",
popupSettings.getPopupJavaScript()));
return;
Expand All @@ -431,7 +433,7 @@ public void renderHead(IHeaderResponse response)
// generated during page load. This check ensures that the click is ignored
response.render(OnEventHeaderItem.forComponent(this, "click",
"var win = this.ownerDocument.defaultView || this.ownerDocument.parentWindow; "
+ "if (win == window) { window.location.href='" + url
+ "if (win == window) { window.location.href='" + escapeQuotesAndBackslash(url)
+ "'; } ;return false"));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import static org.apache.wicket.core.util.string.JavaScriptUtils.escapeQuotesAndBackslash;
import static org.apache.wicket.core.util.string.JavaScriptUtils.unquoteSingleQuoted;


/**
* A popup specification can be used as a property of the {@link Link}classes to specify that the
Expand Down Expand Up @@ -156,10 +159,10 @@ public String getPopupJavaScript()
windowTitle = windowTitle.replaceAll("\\W", "_");
}

var escapedTarget = escapeQuotesAndBackslash(unquoteSingleQuoted(target));
StringBuilder script = new StringBuilder(//
"var w = window.open('"//
+ JavaScriptUtils.escapeQuotes(target) //
+ "', '").append(windowTitle).append("', '");
"var w = window.open('" + escapedTarget + "', '" //
).append(windowTitle).append("', '");

script.append("scrollbars=").append(flagToString(SCROLLBARS));
script.append(",location=").append(flagToString(LOCATION_BAR));
Expand Down