prepare to fix WEB-14454 — Browserify generates incorrect data uri. "charset:" used instead of "charset=" (see https://en.wikipedia.org/wiki/Data_URI_scheme).

This commit is contained in:
Vladimir Krivosheev
2015-06-16 10:04:03 +02:00
parent 3f63e8f58c
commit 79bf32022f
2 changed files with 13 additions and 4 deletions
@@ -44,7 +44,7 @@ public class URLUtil {
public static final String JAR_PROTOCOL = "jar";
public static final String JAR_SEPARATOR = "!/";
public static final Pattern DATA_URI_PATTERN = Pattern.compile("data:([^,;]+/[^,;]+)(;charset=[^,;]+)?(;base64)?,(.+)");
public static final Pattern DATA_URI_PATTERN = Pattern.compile("data:([^,;]+/[^,;]+)(;charset(?:=|:)[^,;]+)?(;base64)?,(.+)");
private URLUtil() { }
@@ -245,4 +245,5 @@ public class URLUtil {
return host;
}
}
@@ -23,12 +23,12 @@
package com.intellij.util.io;
import com.intellij.openapi.util.Pair;
import com.intellij.openapi.vfs.CharsetToolkit;
import org.jetbrains.annotations.Nullable;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.*;
public class UrlUtilTest {
@Test
@@ -72,4 +72,12 @@ public class UrlUtilTest {
assertEquals("github.com", URLUtil.parseHostFromSshUrl(sshUrl));
}
}
@Test
public void testDataUri() {
byte[] test = "test".getBytes(CharsetToolkit.UTF8_CHARSET);
assertThat(URLUtil.getBytesFromDataUri("data:text/plain;charset=utf-8;base64,dGVzdA=="), equalTo(test));
// https://youtrack.jetbrains.com/issue/WEB-14581#comment=27-1014790
assertThat(URLUtil.getBytesFromDataUri("data:text/plain;charset:utf-8;base64,dGVzdA=="), equalTo(test));
}
}