ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/tomcat/util/buf/TesterUriUtilBase.java

Path
ttomcat-1778514358873.zip-extract/apache-tomcat-11.0.18-src/test/org/apache/tomcat/util/buf/TesterUriUtilBase.java
Status
scanned
Type
file
Name
TesterUriUtilBase.java
Extension
.java
Programming language
Java
Mime type
text/plain
File type
ASCII text, with CRLF line terminators
Tag

      
    
Rootfs path

      
    
Size
4882 (4.8 KB)
MD5
715f0bda2b31d239da5c944daf2d879e
SHA1
1538cbf0d6b44c8ddaf36342518393815f8d2bf5
SHA256
75504ebb551aa00ddb2981ff2f85a96f2f52cd49ed4d7ba71d0e3647b512a35f
SHA512

      
    
SHA1_git
a20aad8b7b0f9900803818494c048889e543b6cc
Is binary

      
    
Is text
True
Is archive

      
    
Is media

      
    
Is legal

      
    
Is manifest

      
    
Is readme

      
    
Is top level

      
    
Is key file

      
    
TesterUriUtilBase.java | 4.8 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.tomcat.util.buf; import java.io.File; import java.io.IOException; import java.net.URI; import java.net.URL; import org.junit.Assert; import org.junit.Test; import org.apache.catalina.webresources.TomcatURLStreamHandlerFactory; public abstract class TesterUriUtilBase { private final String separator; protected TesterUriUtilBase(String separator) { this.separator = separator; TomcatURLStreamHandlerFactory.register(); System.setProperty("org.apache.tomcat.util.buf.UriUtil.WAR_SEPARATOR", separator); } @Test public void testBuildJarUrl01() throws IOException { File jarFile = new File("/patha/pathb!/pathc"); String result = UriUtil.buildJarUrl(jarFile).toString(); int index = result.indexOf("!/"); Assert.assertEquals(result, result.length() - 2, index); } @Test public void testBuildJarUrl02() throws IOException { File jarFile = new File("/patha/pathb*/pathc"); String result = UriUtil.buildJarUrl(jarFile).toString(); int index = result.indexOf("!/"); Assert.assertEquals(result, result.length() - 2, index); index = result.indexOf("*/"); Assert.assertEquals(result, -1, index); } @Test public void testBuildJarUrl03() throws IOException { File jarFile = new File("/patha/pathb^/pathc"); String result = UriUtil.buildJarUrl(jarFile).toString(); int index = result.indexOf("!/"); Assert.assertEquals(result, result.length() - 2, index); index = result.indexOf("^/"); Assert.assertEquals(result, -1, index); } @Test public void testBuildJarUrl04() throws IOException { File jarFile = new File("/patha/pathb" + separator + "/pathc"); String result = UriUtil.buildJarUrl(jarFile).toString(); int index = result.indexOf("!/"); Assert.assertEquals(result, result.length() - 2, index); index = result.indexOf(separator + "/"); Assert.assertEquals(result, -1, index); } @Test public void testBuildJarUrl05() throws IOException { File jarFile = new File("/patha/pathb/pathc/war##001.war"); String result = UriUtil.buildJarUrl(jarFile).toString(); int index = result.indexOf("!/"); Assert.assertEquals(result, result.length() - 2, index); index = result.indexOf(separator + "/"); Assert.assertEquals(result, -1, index); // Ensure there is no double decoding // https://bz.apache.org/bugzilla/show_bug.cgi?id=69234 index = result.indexOf("%25"); Assert.assertEquals(result, -1, index); } @Test public void testWarToJar02() throws IOException { doTestWarToJar("*"); } @Test public void testWarToJar03() throws IOException { doTestWarToJar(separator); } private void doTestWarToJar(String separator) throws IOException { URL warUrl = URI.create("war:file:/external/path" + separator + "/internal/path").toURL(); URL jarUrl = UriUtil.warToJar(warUrl); Assert.assertEquals("jar:file:/external/path!/internal/path", jarUrl.toString()); } // @Test /* Uncomment to test performance for different implementations. */ public void performanceTestBuildJarUrl() throws IOException { File jarFile = new File("/patha/pathb^/pathc"); URL url = null; int count = 1000000; // Warm up for (int i = 0; i < count / 10; i++) { url = UriUtil.buildJarUrl(jarFile); } // Test long start = System.nanoTime(); for (int i = 0; i < count / 10; i++) { url = UriUtil.buildJarUrl(jarFile); } long duration = System.nanoTime() - start; System.out.println("[" + count + "] iterations took [" + duration + "] ns for [" + url + "]"); } }
Detected license expression
apache-2.0
Detected license expression (SPDX)
Apache-2.0
Percentage of license text
23.06
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
https://bz.apache.org/bugzilla/show_bug.cgi?id=69234 101 101