diff --git a/src/main/java/org/takes/facets/fork/MediaType.java b/src/main/java/org/takes/facets/fork/MediaType.java index 2d049e87e..cf2ac022d 100644 --- a/src/main/java/org/takes/facets/fork/MediaType.java +++ b/src/main/java/org/takes/facets/fork/MediaType.java @@ -24,6 +24,7 @@ package org.takes.facets.fork; import java.util.Locale; +import java.util.regex.Pattern; import lombok.EqualsAndHashCode; import lombok.ToString; @@ -41,6 +42,11 @@ @EqualsAndHashCode(of = { "high", "low" }) final class MediaType implements Comparable { + /** + * Media type priority clean pattern. + */ + private static final Pattern CLEANER = Pattern.compile("[^0-9\\.]"); + /** * Priority. */ @@ -112,7 +118,7 @@ private static Double priority(final String text) { final String[] parts = MediaType.split(text); final Double priority; if (parts.length > 1) { - final String num = parts[1].replaceAll("[^0-9\\.]", ""); + final String num = CLEANER.matcher(parts[1]).replaceAll(""); if (num.isEmpty()) { priority = 0.0d; } else { diff --git a/src/main/java/org/takes/misc/Href.java b/src/main/java/org/takes/misc/Href.java index 61d252cea..5db977d40 100644 --- a/src/main/java/org/takes/misc/Href.java +++ b/src/main/java/org/takes/misc/Href.java @@ -35,6 +35,7 @@ import java.util.Map; import java.util.SortedMap; import java.util.TreeMap; +import java.util.regex.Pattern; /** * HTTP URI/HREF. @@ -53,6 +54,11 @@ ) public final class Href implements CharSequence { + /** + * Trailer slash pattern. + */ + private static final Pattern TRAILER = Pattern.compile("/$"); + /** * URI (without the query part). */ @@ -195,9 +201,11 @@ public Iterable param(final Object key) { public Href path(final Object suffix) { return new Href( URI.create( - new StringBuilder(this.uri.toString().replaceAll("/$", "")) - .append('/') - .append(Href.encode(suffix.toString())).toString() + new StringBuilder( + TRAILER.matcher(this.uri.toString()).replaceAll("") + ) + .append('/') + .append(Href.encode(suffix.toString())).toString() ), this.params );