mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
fix PathUtil.getFileExtension - dot in the path must be not as ext
This commit is contained in:
@@ -1,18 +1,4 @@
|
||||
/*
|
||||
* Copyright 2000-2017 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed 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.
|
||||
*/
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.util;
|
||||
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
@@ -73,9 +59,7 @@ public class PathUtil {
|
||||
|
||||
@Nullable
|
||||
public static String getFileExtension(@NotNull String name) {
|
||||
int index = name.lastIndexOf('.');
|
||||
if (index < 0) return null;
|
||||
return name.substring(index + 1);
|
||||
return PathUtilRt.getFileExtension(name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -23,7 +23,7 @@ fun flushChunkedResponse(channel: Channel, isKeepAlive: Boolean) {
|
||||
|
||||
object FileResponses {
|
||||
fun getContentType(path: String): String {
|
||||
return fileExtToMimeType.getOrDefault(PathUtilRt.getFileExt(path), "application/octet-stream")
|
||||
return PathUtilRt.getFileExtension(path)?.let { fileExtToMimeType.get(it) } ?: "application/octet-stream"
|
||||
}
|
||||
|
||||
@JvmOverloads
|
||||
|
||||
@@ -26,16 +26,16 @@ public class PathUtilRt {
|
||||
return path.substring(getLastIndexOfPathSeparator(path, end) + 1, end);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String getFileExt(@Nullable String path) {
|
||||
@Nullable
|
||||
public static String getFileExtension(@Nullable String path) {
|
||||
if (StringUtilRt.isEmpty(path)) {
|
||||
return "";
|
||||
return null;
|
||||
}
|
||||
|
||||
int end = getEnd(path);
|
||||
int start = getLastIndexOfPathSeparator(path, end) + 1;
|
||||
int index = StringUtilRt.lastIndexOf(path, '.', Math.max(start, 0), end);
|
||||
return index < 0 ? "" : path.substring(index + 1, end);
|
||||
return index < 0 ? null : path.substring(index + 1, end);
|
||||
}
|
||||
|
||||
private static int getEnd(@NotNull String path) {
|
||||
|
||||
@@ -22,10 +22,14 @@ public class PathUtilTest {
|
||||
|
||||
@Test
|
||||
public void fileExt() {
|
||||
assertThat(PathUtilRt.getFileExt("foo.html")).isEqualTo("html");
|
||||
assertThat(PathUtilRt.getFileExt("foo.html/")).isEqualTo("html");
|
||||
assertThat(PathUtilRt.getFileExt("/foo.html/")).isEqualTo("html");
|
||||
assertThat(PathUtilRt.getFileExt("/bar/foo.html/")).isEqualTo("html");
|
||||
assertThat(PathUtilRt.getFileExtension("foo.html")).isEqualTo("html");
|
||||
assertThat(PathUtilRt.getFileExtension("foo.html/")).isEqualTo("html");
|
||||
assertThat(PathUtilRt.getFileExtension("/foo.html/")).isEqualTo("html");
|
||||
assertThat(PathUtilRt.getFileExtension("/bar/foo.html/")).isEqualTo("html");
|
||||
assertThat(PathUtilRt.getFileExtension("")).isNull();
|
||||
assertThat(PathUtilRt.getFileExtension("foo")).isNull();
|
||||
assertThat(PathUtilRt.getFileExtension("foo.or.bar/bar")).isNull();
|
||||
assertThat(PathUtilRt.getFileExtension("foo.")).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user