ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/catalina/util/TestURLEncoder.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/catalina/util/TestURLEncoder.java
Status
scanned
Type
file
Name
TestURLEncoder.java
Extension
.java
Programming language
Java
Mime type
text/x-Algol68
File type
Algol 68 source, ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
2988 (2.9 KB)
MD5
8e93b09eeedcf18bf8bdce007b805477
SHA1
b21521536fd7ac67f03185b6021370efc478771d
SHA256
d8a79fe7cfc27bfef7d770528edf33a90a3260dc80056332ea5bb85beaa825fd
SHA512

      
    
SHA1_git
024bee163cf06e5e240eb98e592d06a553065953
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TestURLEncoder.java | 2.9 KB |

/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You under the Apache License, Version 2.0 * (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package org.apache.catalina.util; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import org.junit.Assert; import org.junit.Test; import org.apache.tomcat.util.buf.UDecoder; public class TestURLEncoder { private static final String SPACE = " "; private static final String DOLLAR = "$"; private static final String AMPERSAND = "&"; private static final String AMPERSAND_ENCODED = "%26"; @Test public void testClone() { URLEncoder original = new URLEncoder(); URLEncoder clone = (URLEncoder) original.clone(); // Ensure encode as space is not shared original.setEncodeSpaceAsPlus(true); Assert.assertNotEquals(original.encode(SPACE, StandardCharsets.UTF_8), clone.encode(SPACE, StandardCharsets.UTF_8)); // Ensure safe characters is not shared original.addSafeCharacter('$'); Assert.assertNotEquals(original.encode(DOLLAR, StandardCharsets.UTF_8), clone.encode(DOLLAR, StandardCharsets.UTF_8)); } @Test public void testRemoveSafeCharacter() { URLEncoder xml = (URLEncoder) URLEncoder.DEFAULT.clone(); // This should not encode '&' Assert.assertEquals(AMPERSAND, xml.encode(AMPERSAND, StandardCharsets.UTF_8)); xml.removeSafeCharacter('&'); Assert.assertEquals(AMPERSAND_ENCODED, xml.encode(AMPERSAND, StandardCharsets.UTF_8)); } @Test(expected = IllegalArgumentException.class) public void testOssFuzz01() { /* * Round-trip URL encoding with ASCII only works for valid ASCII characters. */ testRoundTrip("\uFFFD", StandardCharsets.US_ASCII); } @Test public void testOssFuzz02() { testRoundTrip("\uFFFD", StandardCharsets.UTF_8); } private void testRoundTrip(String input, Charset charset) { URLEncoder encoder = new URLEncoder(); String encoded = encoder.encode(input, charset); String decoded = UDecoder.URLDecode(encoded, charset); Assert.assertEquals(input, decoded); } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
36.5
Copyrights

      
    
Holders

      
    
Authors

      
    
License detections License expression License expression SPDX
apache_2_0-4bde3f57-78aa-4201-96bf-531cba09e7de apache-2.0 Apache-2.0
URL Start line End line
http://www.apache.org/licenses/LICENSE-2.0 9 9