mirror of https://github.com/shred/acme4j
Use en locale for uppercase/lowercase (fixes #156)
parent
bbc057b81f
commit
511954171d
|
@ -14,6 +14,7 @@
|
||||||
package org.shredzone.acme4j;
|
package org.shredzone.acme4j;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An enumeration of status codes of challenges and authorizations.
|
* An enumeration of status codes of challenges and authorizations.
|
||||||
|
@ -84,7 +85,7 @@ public enum Status {
|
||||||
* no match
|
* no match
|
||||||
*/
|
*/
|
||||||
public static Status parse(String str) {
|
public static Status parse(String str) {
|
||||||
var check = str.toUpperCase();
|
var check = str.toUpperCase(Locale.ENGLISH);
|
||||||
return Arrays.stream(values())
|
return Arrays.stream(values())
|
||||||
.filter(s -> s.name().equals(check))
|
.filter(s -> s.name().equals(check))
|
||||||
.findFirst()
|
.findFirst()
|
||||||
|
|
|
@ -183,7 +183,7 @@ public final class AcmeUtils {
|
||||||
*/
|
*/
|
||||||
public static String toAce(String domain) {
|
public static String toAce(String domain) {
|
||||||
Objects.requireNonNull(domain, "domain");
|
Objects.requireNonNull(domain, "domain");
|
||||||
return IDN.toASCII(domain.trim()).toLowerCase();
|
return IDN.toASCII(domain.trim()).toLowerCase(Locale.ENGLISH);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -307,7 +307,7 @@ public final class AcmeUtils {
|
||||||
if (charset != null && !"utf-8".equalsIgnoreCase(charset)) {
|
if (charset != null && !"utf-8".equalsIgnoreCase(charset)) {
|
||||||
throw new AcmeProtocolException("Unsupported charset " + charset);
|
throw new AcmeProtocolException("Unsupported charset " + charset);
|
||||||
}
|
}
|
||||||
return m.group(1).trim().toLowerCase();
|
return m.group(1).trim().toLowerCase(Locale.ENGLISH);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
|
|
|
@ -15,6 +15,8 @@ package org.shredzone.acme4j;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import java.util.Locale;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,8 +29,11 @@ public class StatusTest {
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testParse() {
|
public void testParse() {
|
||||||
|
// Would break toUpperCase() if English locale is not set, see #156.
|
||||||
|
Locale.setDefault(new Locale("tr"));
|
||||||
|
|
||||||
for (var s : Status.values()) {
|
for (var s : Status.values()) {
|
||||||
var parsed = Status.parse(s.name().toLowerCase());
|
var parsed = Status.parse(s.name().toLowerCase(Locale.ENGLISH));
|
||||||
assertThat(parsed).isEqualTo(s);
|
assertThat(parsed).isEqualTo(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,7 @@ import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Enumeration;
|
import java.util.Enumeration;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
|
@ -74,7 +75,7 @@ public class SignedMail implements Mail {
|
||||||
while (en.hasMoreElements()) {
|
while (en.hasMoreElements()) {
|
||||||
var h = en.nextElement();
|
var h = en.nextElement();
|
||||||
var name = h.getName();
|
var name = h.getName();
|
||||||
if (IGNORE_HEADERS.contains(name.toUpperCase())) {
|
if (IGNORE_HEADERS.contains(name.toUpperCase(Locale.ENGLISH))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -95,7 +96,7 @@ public class SignedMail implements Mail {
|
||||||
while (en.hasMoreElements()) {
|
while (en.hasMoreElements()) {
|
||||||
var h = en.nextElement();
|
var h = en.nextElement();
|
||||||
var name = h.getName();
|
var name = h.getName();
|
||||||
if (IGNORE_HEADERS.contains(name.toUpperCase())) {
|
if (IGNORE_HEADERS.contains(name.toUpperCase(Locale.ENGLISH))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -122,7 +123,7 @@ public class SignedMail implements Mail {
|
||||||
while (en.hasMoreElements()) {
|
while (en.hasMoreElements()) {
|
||||||
var h = en.nextElement();
|
var h = en.nextElement();
|
||||||
var name = h.getName();
|
var name = h.getName();
|
||||||
if (IGNORE_HEADERS.contains(name.toUpperCase())) {
|
if (IGNORE_HEADERS.contains(name.toUpperCase(Locale.ENGLISH))) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -252,7 +253,7 @@ public class SignedMail implements Mail {
|
||||||
.filter(mh -> "AUTO-SUBMITTED".equalsIgnoreCase(mh.name))
|
.filter(mh -> "AUTO-SUBMITTED".equalsIgnoreCase(mh.name))
|
||||||
.map(mh -> mh.value)
|
.map(mh -> mh.value)
|
||||||
.map(String::trim)
|
.map(String::trim)
|
||||||
.map(String::toLowerCase)
|
.map(mh -> mh.toLowerCase(Locale.ENGLISH))
|
||||||
.anyMatch(h -> h.equals("auto-generated") || h.startsWith("auto-generated;"));
|
.anyMatch(h -> h.equals("auto-generated") || h.startsWith("auto-generated;"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -266,7 +267,7 @@ public class SignedMail implements Mail {
|
||||||
headers.stream()
|
headers.stream()
|
||||||
.filter(mh -> mh.trusted)
|
.filter(mh -> mh.trusted)
|
||||||
.map(mh -> mh.name)
|
.map(mh -> mh.name)
|
||||||
.map(String::toUpperCase)
|
.map(mh -> mh.toUpperCase(Locale.ENGLISH))
|
||||||
.forEach(missing::remove);
|
.forEach(missing::remove);
|
||||||
return missing;
|
return missing;
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ import static java.util.stream.Collectors.toUnmodifiableList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
import java.util.Locale;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import jakarta.mail.Message;
|
import jakarta.mail.Message;
|
||||||
|
@ -136,7 +137,7 @@ public class SimpleMail implements Mail {
|
||||||
}
|
}
|
||||||
return Arrays.stream(autoSubmitted)
|
return Arrays.stream(autoSubmitted)
|
||||||
.map(String::trim)
|
.map(String::trim)
|
||||||
.map(String::toLowerCase)
|
.map(as -> as.toLowerCase(Locale.ENGLISH))
|
||||||
.anyMatch(h -> h.equals("auto-generated") || h.startsWith("auto-generated;"));
|
.anyMatch(h -> h.equals("auto-generated") || h.startsWith("auto-generated;"));
|
||||||
} catch (MessagingException ex) {
|
} catch (MessagingException ex) {
|
||||||
throw new AcmeInvalidMessageException("Could not read '" + HEADER_AUTO_SUBMITTED + "' header", ex);
|
throw new AcmeInvalidMessageException("Could not read '" + HEADER_AUTO_SUBMITTED + "' header", ex);
|
||||||
|
|
Loading…
Reference in New Issue