Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests for issue #687 #688

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
31 changes: 30 additions & 1 deletion api/src/test/java/jakarta/mail/internet/ParameterListTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static void before() {
public void testBackslash() throws Exception {
System.clearProperty("mail.mime.windowsfilenames");
ParameterList pl = new ParameterList("; filename=\"\\a\\b\\c.txt\"");
assertEquals(pl.get("filename"), "abc.txt");
assertEquals("abc.txt", pl.get("filename"));
}

/**
Expand Down Expand Up @@ -71,4 +71,33 @@ public void testLongSet() throws Exception {
assertTrue(pls.indexOf("p*0=") >= 0);
assertTrue(pls.indexOf("p*1=") >= 0);
}

@Test
public void testUtf8() throws Exception {
String disposition = ";\n" +
" filename*0*=utf-8''XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX--111111111-XXXXXXXXXXX;\n" +
" filename*1*=XXXXXXXXXXXXXXXXXXXXXXXXXXX.pdf";
ParameterList parameterList = new ParameterList(disposition);
assertEquals("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX--111111111-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.pdf", parameterList.get("filename"));
}

@Test
public void testQEncoding() throws Exception {
String disposition = ";\n" +
" filename==?utf-8?Q?XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX--111111111-XXXXXXXXXXXXXXXXXXX?=\n" +
Copy link
Contributor

@lukasj lukasj Jan 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

filename==?utf-8?Q?X... is invalid - it is missing *, it should be filename*==?utf-8?Q?X..., so the failure here is actually correct behaviour

" =?utf-8?Q?XXXXXXXXXXXXXXXXXXX=2Epdf?=;";
ParameterList parameterList = new ParameterList(disposition);
assertEquals("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX--111111111-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.pdf", parameterList.get("filename"));
}

@Test
public void testQEncodingAndUtf8() throws Exception {
String disposition = ";\n" +
" filename==?utf-8?Q?XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX--111111111-XXXXXXXXXXXXXXXXXXX?=\n" +
" =?utf-8?Q?XXXXXXXXXXXXXXXXXXX=2Epdf?=;\n" +
" filename*0*=utf-8''XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX--111111111-XXXXXXXXXXX;\n" +
" filename*1*=XXXXXXXXXXXXXXXXXXXXXXXXXXX.pdf";
Copy link
Contributor

@lukasj lukasj Jan 6, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could probably be handled in a way that if there is a valid variant of the parameter then ignore (and just log) the invalid one in non-string operation mode or through some new, different property.

An implementation of this would probably need adding a property to ParameterList to keep track of decoded parameters and tweak the behaviour of combineMultisegmentNames method

ParameterList parameterList = new ParameterList(disposition);
assertEquals("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX--111111111-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.pdf", parameterList.get("filename"));
}
}