/** * Decode the given encoded URI component. * <p>See {@link StringUtils#uriDecode(String, Charset)} for the decoding rules. * @param source the encoded String * @param charset the character encoding to use * @return the decoded value * @throws IllegalArgumentException when the given source contains invalid encoded sequences * @since 5.0 * @see StringUtils#uriDecode(String, Charset) * @see java.net.URLDecoder#decode(String, String) */ public static String decode(String source, Charset charset) { return StringUtils.uriDecode(source, charset); }
/** * Decode the given encoded URI component. * <p>See {@link StringUtils#uriDecode(String, Charset)} for the decoding rules. * @param source the encoded String * @param encoding the character encoding to use * @return the decoded value * @throws IllegalArgumentException when the given source contains invalid encoded sequences * @see StringUtils#uriDecode(String, Charset) * @see java.net.URLDecoder#decode(String, String) */ public static String decode(String source, String encoding) { return StringUtils.uriDecode(source, Charset.forName(encoding)); }
/** * Decode the given encoded URI component. * <p>See {@link StringUtils#uriDecode(String, Charset)} for the decoding rules. * @param source the encoded String * @param charset the character encoding to use * @return the decoded value * @throws IllegalArgumentException when the given source contains invalid encoded sequences * @since 5.0 * @see StringUtils#uriDecode(String, Charset) * @see java.net.URLDecoder#decode(String, String) */ public static String decode(String source, Charset charset) { return StringUtils.uriDecode(source, charset); }
private static void parsePathParamValues(String input, Charset charset, MultiValueMap<String, String> output) { if (StringUtils.hasText(input)) { int index = input.indexOf('='); if (index != -1) { String name = input.substring(0, index); String value = input.substring(index + 1); for (String v : StringUtils.commaDelimitedListToStringArray(value)) { name = StringUtils.uriDecode(name, charset); if (StringUtils.hasText(name)) { output.add(name, StringUtils.uriDecode(v, charset)); } } } else { String name = StringUtils.uriDecode(input, charset); if (StringUtils.hasText(name)) { output.add(input, ""); } } } }
/** * Decode the given encoded URI component. * <p>See {@link StringUtils#uriDecode(String, Charset)} for the decoding rules. * @param source the encoded String * @param encoding the character encoding to use * @return the decoded value * @throws IllegalArgumentException when the given source contains invalid encoded sequences * @see StringUtils#uriDecode(String, Charset) * @see java.net.URLDecoder#decode(String, String) */ public static String decode(String source, String encoding) { return StringUtils.uriDecode(source, Charset.forName(encoding)); }
private static PathSegment parsePathSegment(String segment) { Charset charset = StandardCharsets.UTF_8; int index = segment.indexOf(';'); if (index == -1) { String valueToMatch = StringUtils.uriDecode(segment, charset); return new DefaultPathSegment(segment, valueToMatch, EMPTY_MAP); } else { String valueToMatch = StringUtils.uriDecode(segment.substring(0, index), charset); String pathParameterContent = segment.substring(index); MultiValueMap<String, String> parameters = parsePathParams(pathParameterContent, charset); return new DefaultPathSegment(segment, valueToMatch, parameters); } }
private static void parsePathParamValues(String input, Charset charset, MultiValueMap<String, String> output) { if (StringUtils.hasText(input)) { int index = input.indexOf('='); if (index != -1) { String name = input.substring(0, index); String value = input.substring(index + 1); for (String v : StringUtils.commaDelimitedListToStringArray(value)) { name = StringUtils.uriDecode(name, charset); if (StringUtils.hasText(name)) { output.add(name, StringUtils.uriDecode(v, charset)); } } } else { String name = StringUtils.uriDecode(input, charset); if (StringUtils.hasText(name)) { output.add(input, ""); } } } }
private boolean isResourceUnderLocation(Resource resource) throws IOException { if (resource.getClass() != this.location.getClass()) { return false; } String resourcePath; String locationPath; if (resource instanceof UrlResource) { resourcePath = resource.getURL().toExternalForm(); locationPath = StringUtils.cleanPath(this.location.getURL().toString()); } else if (resource instanceof ClassPathResource) { resourcePath = ((ClassPathResource) resource).getPath(); locationPath = StringUtils.cleanPath(((ClassPathResource) this.location).getPath()); } else { resourcePath = resource.getURL().getPath(); locationPath = StringUtils.cleanPath(this.location.getURL().getPath()); } if (locationPath.equals(resourcePath)) { return true; } locationPath = (locationPath.endsWith("/") || locationPath.isEmpty() ? locationPath : locationPath + "/"); if (!resourcePath.startsWith(locationPath)) { return false; } if (resourcePath.contains("%") && StringUtils.uriDecode(resourcePath, StandardCharsets.UTF_8).contains("../")) { return false; } return true; }
private static PathSegment parsePathSegment(String segment) { Charset charset = StandardCharsets.UTF_8; int index = segment.indexOf(';'); if (index == -1) { String valueToMatch = StringUtils.uriDecode(segment, charset); return new DefaultPathSegment(segment, valueToMatch, EMPTY_MAP); } else { String valueToMatch = StringUtils.uriDecode(segment.substring(0, index), charset); String pathParameterContent = segment.substring(index); MultiValueMap<String, String> parameters = parsePathParams(pathParameterContent, charset); return new DefaultPathSegment(segment, valueToMatch, parameters); } }
@Override public Mono<Resource> apply(ServerRequest request) { PathContainer pathContainer = request.pathContainer(); if (!this.pattern.matches(pathContainer)) { return Mono.empty(); } pathContainer = this.pattern.extractPathWithinPattern(pathContainer); String path = processPath(pathContainer.value()); if (path.contains("%")) { path = StringUtils.uriDecode(path, StandardCharsets.UTF_8); } if (!StringUtils.hasLength(path) || isInvalidPath(path)) { return Mono.empty(); } try { Resource resource = this.location.createRelative(path); if (resource.exists() && resource.isReadable() && isResourceUnderLocation(resource)) { return Mono.just(resource); } else { return Mono.empty(); } } catch (IOException ex) { throw new UncheckedIOException(ex); } }
/** * Decode the given encoded URI component. * <p>See {@link StringUtils#uriDecode(String, Charset)} for the decoding rules. * @param source the encoded String * @param charset the character encoding to use * @return the decoded value * @throws IllegalArgumentException when the given source contains invalid encoded sequences * @since 5.0 * @see StringUtils#uriDecode(String, Charset) * @see java.net.URLDecoder#decode(String, String) */ public static String decode(String source, Charset charset) { return StringUtils.uriDecode(source, charset); }
/** * Decode the given encoded URI component. * <p>See {@link StringUtils#uriDecode(String, Charset)} for the decoding rules. * * @param source the encoded String * @return the decoded value * @throws IllegalArgumentException when the given source contains invalid encoded sequences * @see StringUtils#uriDecode(String, Charset) * @see java.net.URLDecoder#decode(String, String) */ public static String decode(String source) { return StringUtils.uriDecode(source, Charsets.UTF_8); }
/** * Decode the given encoded URI component. * <p>See {@link StringUtils#uriDecode(String, Charset)} for the decoding rules. * @param source the encoded String * @param charset the character encoding to use * @return the decoded value * @throws IllegalArgumentException when the given source contains invalid encoded sequences * @since 5.0 * @see StringUtils#uriDecode(String, Charset) * @see java.net.URLDecoder#decode(String, String) */ public static String decode(String source, Charset charset) { return StringUtils.uriDecode(source, charset); }
/** * Decode the given encoded URI component. * <p>See {@link StringUtils#uriDecode(String, Charset)} for the decoding rules. * * @param source the encoded String * @param charset the character encoding to use * @return the decoded value * @throws IllegalArgumentException when the given source contains invalid encoded sequences * @see StringUtils#uriDecode(String, Charset) * @see java.net.URLDecoder#decode(String, String) */ public static String decode(String source, Charset charset) { return StringUtils.uriDecode(source, charset); }
/** * Decode the given encoded URI component. * <p>See {@link StringUtils#uriDecode(String, Charset)} for the decoding rules. * @param source the encoded String * @param encoding the character encoding to use * @return the decoded value * @throws IllegalArgumentException when the given source contains invalid encoded sequences * @see StringUtils#uriDecode(String, Charset) * @see java.net.URLDecoder#decode(String, String) */ public static String decode(String source, String encoding) { return StringUtils.uriDecode(source, Charset.forName(encoding)); }
/** * Decode the given encoded URI component. * <p>See {@link StringUtils#uriDecode(String, Charset)} for the decoding rules. * @param source the encoded String * @param encoding the character encoding to use * @return the decoded value * @throws IllegalArgumentException when the given source contains invalid encoded sequences * @see StringUtils#uriDecode(String, Charset) * @see java.net.URLDecoder#decode(String, String) */ public static String decode(String source, String encoding) { return StringUtils.uriDecode(source, Charset.forName(encoding)); }
private static void parsePathParamValues(String input, Charset charset, MultiValueMap<String, String> output) { if (StringUtils.hasText(input)) { int index = input.indexOf('='); if (index != -1) { String name = input.substring(0, index); String value = input.substring(index + 1); for (String v : StringUtils.commaDelimitedListToStringArray(value)) { name = StringUtils.uriDecode(name, charset); if (StringUtils.hasText(name)) { output.add(name, StringUtils.uriDecode(v, charset)); } } } else { String name = StringUtils.uriDecode(input, charset); if (StringUtils.hasText(name)) { output.add(input, ""); } } } }
private static void parsePathParamValues(String input, Charset charset, MultiValueMap<String, String> output) { if (StringUtils.hasText(input)) { int index = input.indexOf('='); if (index != -1) { String name = input.substring(0, index); String value = input.substring(index + 1); for (String v : StringUtils.commaDelimitedListToStringArray(value)) { name = StringUtils.uriDecode(name, charset); if (StringUtils.hasText(name)) { output.add(name, StringUtils.uriDecode(v, charset)); } } } else { String name = StringUtils.uriDecode(input, charset); if (StringUtils.hasText(name)) { output.add(input, ""); } } } }
private static PathSegment parsePathSegment(String segment) { Charset charset = StandardCharsets.UTF_8; int index = segment.indexOf(';'); if (index == -1) { String valueToMatch = StringUtils.uriDecode(segment, charset); return new DefaultPathSegment(segment, valueToMatch, EMPTY_MAP); } else { String valueToMatch = StringUtils.uriDecode(segment.substring(0, index), charset); String pathParameterContent = segment.substring(index); MultiValueMap<String, String> parameters = parsePathParams(pathParameterContent, charset); return new DefaultPathSegment(segment, valueToMatch, parameters); } }
private static PathSegment parsePathSegment(String segment) { Charset charset = StandardCharsets.UTF_8; int index = segment.indexOf(';'); if (index == -1) { String valueToMatch = StringUtils.uriDecode(segment, charset); return new DefaultPathSegment(segment, valueToMatch, EMPTY_MAP); } else { String valueToMatch = StringUtils.uriDecode(segment.substring(0, index), charset); String pathParameterContent = segment.substring(index); MultiValueMap<String, String> parameters = parsePathParams(pathParameterContent, charset); return new DefaultPathSegment(segment, valueToMatch, parameters); } }