Skip to content
Open
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
43 changes: 19 additions & 24 deletions java/org/apache/tomcat/util/http/WebdavIfHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -585,7 +585,7 @@ protected IfListEntry(String value, boolean positive) {
* matches.
* <p>
* This helper method can be called by implementations to evaluate the concrete match on the correct value
* parameter. See {@link #match(String, String)} for the external API method.
* parameter. See {@link #match(List, String)} for the external API method.
*
* @param value The string value to compare to the {@link #value} field.
*
Expand All @@ -598,17 +598,17 @@ protected boolean match(String value) {
}

/**
* Matches the entry's value to the token or etag. Depending on the concrete implementation, only one of the
* parameters may be evaluated while the other may be ignored.
* Matches the entry's value to the tokens or etag of the resource. Depending on the concrete implementation,
* only one of the parameters may be evaluated while the other may be ignored.
* <p>
* Implementing METHODS may call the helper method {@link #match(String)} for the actual matching.
*
* @param token The token value to compare
* @param etag The etag value to compare
* @param tokens The lock tokens of the resource
* @param etag The etag value to compare
*
* @return <code>true</code> if the token/etag matches the <em>IfList</em> entry.
* @return <code>true</code> if the tokens/etag match the <em>IfList</em> entry.
*/
public abstract boolean match(String token, String etag);
public abstract boolean match(List<String> tokens, String etag);

/**
* Returns a short type name for the implementation. This method is used by the {@link #toString} method to
Expand Down Expand Up @@ -657,17 +657,18 @@ private static class IfListEntryToken extends IfListEntry {
}

/**
* Matches the token parameter to the stored token value and returns <code>true</code> if the values match and
* if the match is positive. <code>true</code> is also returned for negative matches if the values do not match.
* Returns <code>true</code> if the stored token value is one of the tokens of the resource and the match is
* positive. <code>true</code> is also returned for negative matches if the stored token value is not one of
* the tokens of the resource.
*
* @param token The token value to compare
* @param etag The etag value to compare, which is ignored in this implementation.
* @param tokens The lock tokens of the resource
* @param etag The etag value to compare, which is ignored in this implementation.
*
* @return <code>true</code> if the token matches the <em>IfList</em> entry's token value.
* @return <code>true</code> if the tokens match the <em>IfList</em> entry's token value.
*/
@Override
public boolean match(String token, String etag) {
return token == null || super.match(token);
public boolean match(List<String> tokens, String etag) {
return positive == tokens.contains(value);
}

/**
Expand Down Expand Up @@ -701,13 +702,13 @@ private static class IfListEntryEtag extends IfListEntry {
* Matches the etag parameter to the stored etag value and returns <code>true</code> if the values match and if
* the match is positive. <code>true</code> is also returned for negative matches if the values do not match.
*
* @param token The token value to compare, which is ignored in this implementation.
* @param etag The etag value to compare
* @param tokens The lock tokens of the resource, which are ignored in this implementation.
* @param etag The etag value to compare
*
* @return <code>true</code> if the etag matches the <em>IfList</em> entry's etag value.
*/
@Override
public boolean match(String token, String etag) {
public boolean match(List<String> tokens, String etag) {
return super.match(etag);
}

Expand Down Expand Up @@ -777,13 +778,7 @@ public boolean match(List<String> tokens, String etag) {
}
for (int i = 0; i < size(); i++) {
IfListEntry ile = get(i);
boolean match = false;
for (String token : tokens) {
if (ile.match(token, etag)) {
match = true;
}
}
if (!match) {
if (!ile.match(tokens, etag)) {
if (log.isTraceEnabled()) {
log.trace("match: Entry " + i + "-" + ile + " does not match");
}
Expand Down
22 changes: 22 additions & 0 deletions test/org/apache/tomcat/util/http/TestWebdavIfHeader.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
*/
package org.apache.tomcat.util.http;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

Expand Down Expand Up @@ -102,6 +103,27 @@ public void testNotMatches() throws Exception {
Assert.assertTrue(header.matches("/myfolder/", Collections.singletonList("other"), "etag"));
}

@Test
public void testNotMatchesWithoutLocks() throws Exception {
// RFC 4918, section 10.4.3: "Not" reverses the result of the evaluation
WebdavIfHeader header = new WebdavIfHeader(URI_PREFIX, "(Not <" + TOKEN + ">)");
Assert.assertTrue(header.matches("/myfolder/", Collections.emptyList(), "etag"));
// RFC 4918, section 10.4.8: always evaluates to true
header = new WebdavIfHeader(URI_PREFIX, "(Not <DAV:no-lock>)");
Assert.assertTrue(header.matches("/myfolder/", Collections.emptyList(), "etag"));
header = new WebdavIfHeader(URI_PREFIX, "(<" + TOKEN + ">)");
Assert.assertFalse(header.matches("/myfolder/", Collections.emptyList(), "etag"));
header = new WebdavIfHeader(URI_PREFIX, "([etag])");
Assert.assertTrue(header.matches("/myfolder/", Collections.emptyList(), "etag"));
}

@Test
public void testNotMatchesWithSeveralLocks() throws Exception {
WebdavIfHeader header = new WebdavIfHeader(URI_PREFIX, "(Not <" + TOKEN + ">)");
Assert.assertFalse(header.matches("/myfolder/", Arrays.asList("other", TOKEN), "etag"));
Assert.assertTrue(header.matches("/myfolder/", Arrays.asList("other", "another"), "etag"));
}

/*
* The parser is deliberately lenient with malformed entries that do not prevent the rest of the header from
* parsing (error recovery inherited from the Jackrabbit code). Only a list without any valid entry invalidates
Expand Down
Loading