Skip to content

Commit

Permalink
SHRINKDESC-51: Allow for escaping slashes in node queries.
Browse files Browse the repository at this point in the history
  • Loading branch information
m1key authored and ALRubinger committed Sep 15, 2011
1 parent b292e0c commit b12a8c8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
*/
class Patterns
{
private static final String PATH_SEPARATOR = "/";
private static final String PATH_SEPARATOR = "(?<!\\\\)[/]";

private static final String ATTR_PATH_SEPERATOR = "@";

Expand All @@ -53,7 +53,7 @@ public static Pattern[] from(final String queryExpression) throws IllegalArgumen
throw new IllegalArgumentException("Query expression must be specified");
}

boolean isAbsolute = queryExpression.startsWith(PATH_SEPARATOR);
boolean isAbsolute = queryExpression.startsWith("/");
final Collection<Pattern> patterns = new ArrayList<Pattern>();

final String[] paths = (isAbsolute ? queryExpression.substring(1) : queryExpression).split(PATH_SEPARATOR);
Expand All @@ -65,7 +65,7 @@ public static Pattern[] from(final String queryExpression) throws IllegalArgumen
String name = nameSegment.indexOf(ATTR_VALUE_SEPERATOR) != -1 ? nameSegment.substring(0,
nameSegment.indexOf(ATTR_VALUE_SEPERATOR)) : nameSegment;
String text = nameSegment.indexOf(ATTR_VALUE_SEPERATOR) != -1 ? nameSegment.substring(nameSegment
.indexOf(ATTR_VALUE_SEPERATOR) + 1) : null;
.indexOf(ATTR_VALUE_SEPERATOR) + 1).replaceAll("\\\\", "") : null;
String attribute = path.indexOf(ATTR_PATH_SEPERATOR) != -1 ? path.substring(path.indexOf(ATTR_PATH_SEPERATOR)
+ ATTR_PATH_SEPERATOR.length(), path.length()) : null;
String[] attributes = attribute == null ? new String[0] : attribute.split(ATTR_SEPERATOR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -621,4 +621,21 @@ public void shouldBeAbleToGetNodeWithTextValues()
Assert.assertEquals("Verify root only has four children", 4, root.getChildren().size());
}

@Test
public void shouldBeAbleToCreateNodeWithValueWithEqualsInIt()
{
String child3Value = "omg\\/with\\/slashes";
String child3ValueNotEscaped = "omg/with/slashes";
// given
Node root = new Node(ROOT_NODE);
root.getOrCreate(("/" + CHILD_2_NODE + "/" + CHILD_3_NODE + "=" + child3Value));

// when
Node found = root.getSingle(("/" + CHILD_2_NODE + "/" + CHILD_3_NODE));

// then
Assert.assertNotNull("Verify node was found", found);
Assert.assertEquals("Verify correct value set", child3ValueNotEscaped, found.getText());
}

}

0 comments on commit b12a8c8

Please sign in to comment.