This is an automated email from the ASF dual-hosted git repository. chibenwa pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/james-mime4j.git
commit 9cf2c03053bbefde6178a4921151890f471e52d4 Author: Benoit TELLIER <[email protected]> AuthorDate: Fri Nov 13 13:54:26 2026 +0100 [FIX] ContentLocationFieldImpl: a form feed or vertical tab in the URL is kept The strict parser removed the whitespace of the URL with the regex "\s", which also matches form feed and vertical tab, while the lenient one removes only SP, HTAB, CR and LF (CharsetUtil#isWhitespace). So "Content-Location: a/\fb" gave "a/b" on the strict path (DefaultFieldParser, MaximalBodyDescriptor) and "a/\fb" on the lenient DOM path. RFC 2017 drops linear whitespace, and FF/VT are control characters, not whitespace: the strict parser now removes the same four characters as the lenient one. Fixes #132 --- .../apache/james/mime4j/field/ContentLocationFieldImpl.java | 2 +- .../apache/james/mime4j/field/ContentLocationFieldTest.java | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/dom/src/main/java/org/apache/james/mime4j/field/ContentLocationFieldImpl.java b/dom/src/main/java/org/apache/james/mime4j/field/ContentLocationFieldImpl.java index aa27b008..b603e9e1 100644 --- a/dom/src/main/java/org/apache/james/mime4j/field/ContentLocationFieldImpl.java +++ b/dom/src/main/java/org/apache/james/mime4j/field/ContentLocationFieldImpl.java @@ -33,7 +33,7 @@ import org.apache.james.mime4j.stream.Field; * Represents a <code>Content-Location</code> field. */ public class ContentLocationFieldImpl extends AbstractField implements ContentLocationField { - private static final Pattern PATTERN = Pattern.compile("\\s"); + private static final Pattern PATTERN = Pattern.compile("[ \\t\\r\\n]"); private boolean parsed = false; private String location; diff --git a/dom/src/test/java/org/apache/james/mime4j/field/ContentLocationFieldTest.java b/dom/src/test/java/org/apache/james/mime4j/field/ContentLocationFieldTest.java index 85f18c7a..34eeb8d2 100644 --- a/dom/src/test/java/org/apache/james/mime4j/field/ContentLocationFieldTest.java +++ b/dom/src/test/java/org/apache/james/mime4j/field/ContentLocationFieldTest.java @@ -101,4 +101,15 @@ public class ContentLocationFieldTest extends TestCase { assertEquals(value, lenient.getLocation(), strict.getLocation()); } } + + public void testFormFeedAndVerticalTabAreKeptLikeTheLenientParser() throws Exception { + String[] values = {"a/\fb", "a/\u000Bb", "a /\f b"}; + for (String value : values) { + ContentLocationField strict = parse("Content-Location: " + value); + ContentLocationField lenient = LenientContentLocationFieldTest.parse("Content-Location: " + value); + assertNull(strict.getParseException()); + assertEquals(value, lenient.getLocation(), strict.getLocation()); + } + assertEquals("a/\fb", parse("Content-Location: a/\fb").getLocation()); + } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
