Author: radu
Date: Fri Jul 8 09:30:19 2016
New Revision: 1751874
URL: http://svn.apache.org/viewvc?rev=1751874&view=rev
Log:
SLING-5632 - [Sightly] URI manipulation options that process a path should not
alter URIs that don't provide path information
* disallow further processing by path-related options if the original URI
doesn't contain a path information or if the path
option is empty
* updated TCK version since the new version provides more tests related to URI
manipulation options
Modified:
sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/URIManipulationFilterExtension.java
sling/trunk/bundles/scripting/sightly/testing-content/pom.xml
sling/trunk/bundles/scripting/sightly/testing/pom.xml
Modified:
sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/URIManipulationFilterExtension.java
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/URIManipulationFilterExtension.java?rev=1751874&r1=1751873&r2=1751874&view=diff
==============================================================================
---
sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/URIManipulationFilterExtension.java
(original)
+++
sling/trunk/bundles/scripting/sightly/engine/src/main/java/org/apache/sling/scripting/sightly/impl/engine/extension/URIManipulationFilterExtension.java
Fri Jul 8 09:30:19 2016
@@ -94,79 +94,89 @@ public class URIManipulationFilterExtens
if (prependPath == null) {
prependPath = StringUtils.EMPTY;
}
- if (StringUtils.isNotEmpty(prependPath)) {
- if (sb.length() > 0 && !prependPath.startsWith("/")) {
- prependPath = "/" + prependPath;
- }
- if (!prependPath.endsWith("/")) {
- prependPath += "/";
- }
- }
String path = getOption(PATH, options, pathInfo.getPath());
if (StringUtils.isEmpty(path)) {
// if the path is forced to be empty don't remove the path
path = pathInfo.getPath();
}
- String appendPath = getOption(APPEND_PATH, options, StringUtils.EMPTY);
- if (appendPath == null) {
- appendPath = StringUtils.EMPTY;
- }
- if (StringUtils.isNotEmpty(appendPath)) {
- if (!appendPath.startsWith("/")) {
- appendPath = "/" + appendPath;
+ if (StringUtils.isNotEmpty(path) && !"/".equals(path)) {
+ if (StringUtils.isNotEmpty(prependPath)) {
+ if (sb.length() > 0 && !prependPath.startsWith("/")) {
+ prependPath = "/" + prependPath;
+ }
+ if (!prependPath.endsWith("/")) {
+ prependPath += "/";
+ }
}
- }
- String newPath;
- try {
- newPath = new URI(prependPath + path +
appendPath).normalize().getPath();
- } catch (URISyntaxException e) {
- newPath = prependPath + path + appendPath;
- }
- if (sb.length() > 0 && sb.lastIndexOf("/") != sb.length() - 1 &&
StringUtils.isNotEmpty(newPath) && !newPath.startsWith("/")) {
- sb.append("/");
- }
- sb.append(newPath);
- Set<String> selectors = pathInfo.getSelectors();
- handleSelectors(runtimeObjectModel, selectors, options);
- for (String selector : selectors) {
- if (StringUtils.isNotBlank(selector) && !selector.contains(" ")) {
- // make sure not to append empty or invalid selectors
- sb.append(".").append(selector);
- }
- }
- String extension = getOption(EXTENSION, options,
pathInfo.getExtension());
- if (StringUtils.isNotEmpty(extension)) {
- sb.append(".").append(extension);
- }
- String prependSuffix = getOption(PREPEND_SUFFIX, options,
StringUtils.EMPTY);
- if (StringUtils.isNotEmpty(prependSuffix)) {
- if (!prependSuffix.startsWith("/")) {
- prependSuffix = "/" + prependSuffix;
- }
- if (!prependSuffix.endsWith("/")) {
- prependSuffix += "/";
+
+ String appendPath = getOption(APPEND_PATH, options,
StringUtils.EMPTY);
+ if (appendPath == null) {
+ appendPath = StringUtils.EMPTY;
+ }
+ if (StringUtils.isNotEmpty(appendPath)) {
+ if (!appendPath.startsWith("/")) {
+ appendPath = "/" + appendPath;
+ }
+ }
+ String newPath;
+ try {
+ newPath = new URI(prependPath + path +
appendPath).normalize().getPath();
+ } catch (URISyntaxException e) {
+ newPath = prependPath + path + appendPath;
}
- }
- String pathInfoSuffix = pathInfo.getSuffix();
- String suffix = getOption(SUFFIX, options, pathInfoSuffix == null ?
StringUtils.EMPTY : pathInfoSuffix);
- if (suffix == null) {
- suffix = StringUtils.EMPTY;
- }
- String appendSuffix = getOption(APPEND_SUFFIX, options,
StringUtils.EMPTY);
- if (StringUtils.isNotEmpty(appendSuffix)) {
- appendSuffix = "/" + appendSuffix;
- }
- String newSuffix = FilenameUtils.normalize(prependSuffix + suffix +
appendSuffix, true);
- if (StringUtils.isNotEmpty(newSuffix)) {
- if (!newSuffix.startsWith("/")) {
+ if (sb.length() > 0 && sb.lastIndexOf("/") != sb.length() - 1 &&
StringUtils.isNotEmpty(newPath) && !newPath.startsWith("/")) {
sb.append("/");
}
- sb.append(newSuffix);
+ sb.append(newPath);
+ Set<String> selectors = pathInfo.getSelectors();
+ handleSelectors(runtimeObjectModel, selectors, options);
+ for (String selector : selectors) {
+ if (StringUtils.isNotBlank(selector) && !selector.contains("
")) {
+ // make sure not to append empty or invalid selectors
+ sb.append(".").append(selector);
+ }
+ }
+ String extension = getOption(EXTENSION, options,
pathInfo.getExtension());
+ if (StringUtils.isNotEmpty(extension)) {
+ sb.append(".").append(extension);
+ }
+
+ String prependSuffix = getOption(PREPEND_SUFFIX, options,
StringUtils.EMPTY);
+ if (StringUtils.isNotEmpty(prependSuffix)) {
+ if (!prependSuffix.startsWith("/")) {
+ prependSuffix = "/" + prependSuffix;
+ }
+ if (!prependSuffix.endsWith("/")) {
+ prependSuffix += "/";
+ }
+ }
+ String pathInfoSuffix = pathInfo.getSuffix();
+ String suffix = getOption(SUFFIX, options, pathInfoSuffix == null
? StringUtils.EMPTY : pathInfoSuffix);
+ if (suffix == null) {
+ suffix = StringUtils.EMPTY;
+ }
+ String appendSuffix = getOption(APPEND_SUFFIX, options,
StringUtils.EMPTY);
+ if (StringUtils.isNotEmpty(appendSuffix)) {
+ appendSuffix = "/" + appendSuffix;
+ }
+ String newSuffix = FilenameUtils.normalize(prependSuffix + suffix
+ appendSuffix, true);
+ if (StringUtils.isNotEmpty(newSuffix)) {
+ if (!newSuffix.startsWith("/")) {
+ sb.append("/");
+ }
+ sb.append(newSuffix);
+ }
+
+ } else if ("/".equals(path)) {
+ sb.append(path);
}
Map<String, Collection<String>> parameters = pathInfo.getParameters();
handleParameters(runtimeObjectModel, parameters, options);
- if (!parameters.isEmpty()) {
+ if (sb.length() > 0 && !parameters.isEmpty()) {
+ if (StringUtils.isEmpty(path)) {
+ sb.append("/");
+ }
sb.append("?");
for (Map.Entry<String, Collection<String>> entry :
parameters.entrySet()) {
for (String value : entry.getValue()) {
Modified: sling/trunk/bundles/scripting/sightly/testing-content/pom.xml
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/testing-content/pom.xml?rev=1751874&r1=1751873&r2=1751874&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/testing-content/pom.xml (original)
+++ sling/trunk/bundles/scripting/sightly/testing-content/pom.xml Fri Jul 8
09:30:19 2016
@@ -100,7 +100,7 @@
<artifactItem>
<groupId>io.sightly</groupId>
<artifactId>io.sightly.tck</artifactId>
- <version>1.2.2</version>
+ <version>1.2.3</version>
<type>jar</type>
<outputDirectory>${project.build.directory}/sightlytck/</outputDirectory>
<includes>**/*.html,**/*.js,**/*.java</includes>
Modified: sling/trunk/bundles/scripting/sightly/testing/pom.xml
URL:
http://svn.apache.org/viewvc/sling/trunk/bundles/scripting/sightly/testing/pom.xml?rev=1751874&r1=1751873&r2=1751874&view=diff
==============================================================================
--- sling/trunk/bundles/scripting/sightly/testing/pom.xml (original)
+++ sling/trunk/bundles/scripting/sightly/testing/pom.xml Fri Jul 8 09:30:19
2016
@@ -196,7 +196,7 @@
<dependency>
<groupId>io.sightly</groupId>
<artifactId>io.sightly.tck</artifactId>
- <version>1.2.2</version>
+ <version>1.2.3</version>
<scope>test</scope>
<exclusions>
<exclusion>