提交 f9ce7bf8 authored 作者: christian.peter.io's avatar christian.peter.io

Bugfix for the automatic 1.1 db migration: only uppercase parameters where…

Bugfix for the automatic 1.1 db migration: only uppercase parameters where replaced. If a lowercase parameter like ifexists=true was in the connection url, the upgrade failed.
上级 29a47b41
...@@ -37,6 +37,8 @@ Change Log ...@@ -37,6 +37,8 @@ Change Log
because it was not always working as expected. Now System.gc() is used in a loop until the because it was not always working as expected. Now System.gc() is used in a loop until the
buffer is garbage collected. This of course is also not a nice solution, but the only one known to work. buffer is garbage collected. This of course is also not a nice solution, but the only one known to work.
See also http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4724038 See also http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4724038
</li><li>Bugfix for the automatic 1.1 db migration: only uppercase parameters where replaced. If a lowercase
parameter like ifexists=true was in the connection url, the upgrade failed.
</li><li>If an old 1.1 database file version is found on connect, it is now possible to let the old h2 </li><li>If an old 1.1 database file version is found on connect, it is now possible to let the old h2
classes (v 1.2.128) connect to the database. The automatic upgrade .jar file must be present, and the url classes (v 1.2.128) connect to the database. The automatic upgrade .jar file must be present, and the url
must contain NO_UPGRADE=TRUE must contain NO_UPGRADE=TRUE
......
...@@ -10,6 +10,7 @@ import java.sql.Connection; ...@@ -10,6 +10,7 @@ import java.sql.Connection;
import java.sql.DriverManager; import java.sql.DriverManager;
import java.sql.DriverPropertyInfo; import java.sql.DriverPropertyInfo;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Locale;
import java.util.Properties; import java.util.Properties;
import org.h2.engine.Constants; import org.h2.engine.Constants;
...@@ -17,6 +18,7 @@ import org.h2.jdbc.JdbcConnection; ...@@ -17,6 +18,7 @@ import org.h2.jdbc.JdbcConnection;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.message.TraceSystem; import org.h2.message.TraceSystem;
import org.h2.upgrade.DbUpgrade; import org.h2.upgrade.DbUpgrade;
import org.h2.util.StringUtils;
/** /**
* The database driver. An application should not use this class directly. The * The database driver. An application should not use this class directly. The
...@@ -56,8 +58,8 @@ public class Driver implements java.sql.Driver { ...@@ -56,8 +58,8 @@ public class Driver implements java.sql.Driver {
if (!acceptsURL(url)) { if (!acceptsURL(url)) {
return null; return null;
} }
boolean noUpgrade = url.contains(";NO_UPGRADE=TRUE"); boolean noUpgrade = url.toUpperCase(Locale.ENGLISH).contains(";NO_UPGRADE=TRUE");
url = url.replaceAll(";NO_UPGRADE=TRUE", ""); url = StringUtils.replaceAll(url, ";NO_UPGRADE=TRUE", "", true);
if (DbUpgrade.areV1dot1ClassesPresent()) { if (DbUpgrade.areV1dot1ClassesPresent()) {
if (noUpgrade) { if (noUpgrade) {
Connection connection = DbUpgrade.connectWithOldVersion(url, info); Connection connection = DbUpgrade.connectWithOldVersion(url, info);
......
...@@ -230,21 +230,21 @@ public class Bnf { ...@@ -230,21 +230,21 @@ public class Bnf {
private String[] tokenize() { private String[] tokenize() {
ArrayList<String> list = New.arrayList(); ArrayList<String> list = New.arrayList();
syntax = StringUtils.replaceAll(syntax, "yyyy-MM-dd", "@ymd@"); syntax = StringUtils.replaceAll(syntax, "yyyy-MM-dd", "@ymd@", false);
syntax = StringUtils.replaceAll(syntax, "hh:mm:ss", "@hms@"); syntax = StringUtils.replaceAll(syntax, "hh:mm:ss", "@hms@", false);
syntax = StringUtils.replaceAll(syntax, "nnnnnnnnn", "@nanos@"); syntax = StringUtils.replaceAll(syntax, "nnnnnnnnn", "@nanos@", false);
syntax = StringUtils.replaceAll(syntax, "function", "@func@"); syntax = StringUtils.replaceAll(syntax, "function", "@func@", false);
syntax = StringUtils.replaceAll(syntax, "0x", "@hexStart@"); syntax = StringUtils.replaceAll(syntax, "0x", "@hexStart@", false);
syntax = StringUtils.replaceAll(syntax, ",...", "@commaDots@"); syntax = StringUtils.replaceAll(syntax, ",...", "@commaDots@", false);
syntax = StringUtils.replaceAll(syntax, "...", "@dots@"); syntax = StringUtils.replaceAll(syntax, "...", "@dots@", false);
syntax = StringUtils.replaceAll(syntax, "||", "@concat@"); syntax = StringUtils.replaceAll(syntax, "||", "@concat@", false);
syntax = StringUtils.replaceAll(syntax, "a-z|_", "@az_@"); syntax = StringUtils.replaceAll(syntax, "a-z|_", "@az_@", false);
syntax = StringUtils.replaceAll(syntax, "A-Z|_", "@az_@"); syntax = StringUtils.replaceAll(syntax, "A-Z|_", "@az_@", false);
syntax = StringUtils.replaceAll(syntax, "a-f", "@af@"); syntax = StringUtils.replaceAll(syntax, "a-f", "@af@", false);
syntax = StringUtils.replaceAll(syntax, "A-F", "@af@"); syntax = StringUtils.replaceAll(syntax, "A-F", "@af@", false);
syntax = StringUtils.replaceAll(syntax, "0-9", "@digit@"); syntax = StringUtils.replaceAll(syntax, "0-9", "@digit@", false);
syntax = StringUtils.replaceAll(syntax, "'['", "@openBracket@"); syntax = StringUtils.replaceAll(syntax, "'['", "@openBracket@", false);
syntax = StringUtils.replaceAll(syntax, "']'", "@closeBracket@"); syntax = StringUtils.replaceAll(syntax, "']'", "@closeBracket@", false);
StringTokenizer tokenizer = getTokenizer(syntax); StringTokenizer tokenizer = getTokenizer(syntax);
while (tokenizer.hasMoreTokens()) { while (tokenizer.hasMoreTokens()) {
String s = tokenizer.nextToken(); String s = tokenizer.nextToken();
......
...@@ -2380,7 +2380,7 @@ public class Parser { ...@@ -2380,7 +2380,7 @@ public class Parser {
String text = currentValue.getString(); String text = currentValue.getString();
// the PostgreSQL ODBC driver uses // the PostgreSQL ODBC driver uses
// LIKE E'PROJECT\\_DATA' instead of LIKE 'PROJECT\_DATA' // LIKE E'PROJECT\\_DATA' instead of LIKE 'PROJECT\_DATA'
text = StringUtils.replaceAll(text, "\\\\", "\\"); text = StringUtils.replaceAll(text, "\\\\", "\\", false);
read(); read();
r = ValueExpression.get(ValueString.get(text)); r = ValueExpression.get(ValueString.get(text));
} else { } else {
......
...@@ -63,7 +63,7 @@ public class CreateFunctionAlias extends SchemaCommand { ...@@ -63,7 +63,7 @@ public class CreateFunctionAlias extends SchemaCommand {
* @param method the qualified method name * @param method the qualified method name
*/ */
public void setJavaClassMethod(String method) { public void setJavaClassMethod(String method) {
this.javaClassMethod = StringUtils.replaceAll(method, " ", ""); this.javaClassMethod = StringUtils.replaceAll(method, " ", "", false);
} }
public void setIfNotExists(boolean ifNotExists) { public void setIfNotExists(boolean ifNotExists) {
......
...@@ -304,9 +304,9 @@ public class WebApp { ...@@ -304,9 +304,9 @@ public class WebApp {
value = space + value; value = space + value;
} }
key = StringUtils.urlEncode(key); key = StringUtils.urlEncode(key);
key = StringUtils.replaceAll(key, "+", " "); key = StringUtils.replaceAll(key, "+", " ", false);
value = StringUtils.urlEncode(value); value = StringUtils.urlEncode(value);
value = StringUtils.replaceAll(value, "+", " "); value = StringUtils.replaceAll(value, "+", " ", false);
list.add(type + "#" + key + "#" + value); list.add(type + "#" + key + "#" + value);
} }
Collections.sort(list); Collections.sort(list);
...@@ -738,7 +738,7 @@ public class WebApp { ...@@ -738,7 +738,7 @@ public class WebApp {
if (isH2) { if (isH2) {
stackTrace = linkToSource(stackTrace); stackTrace = linkToSource(stackTrace);
} }
stackTrace = StringUtils.replaceAll(stackTrace, "\t", "&nbsp;&nbsp;&nbsp;&nbsp;"); stackTrace = StringUtils.replaceAll(stackTrace, "\t", "&nbsp;&nbsp;&nbsp;&nbsp;", false);
String message = PageParser.escapeHtml(e.getMessage()); String message = PageParser.escapeHtml(e.getMessage());
String error = "<a class=\"error\" href=\"#\" onclick=\"var x=document.getElementById('st" + id String error = "<a class=\"error\" href=\"#\" onclick=\"var x=document.getElementById('st" + id
+ "').style;x.display=x.display==''?'none':'';\">" + message + "</a>"; + "').style;x.display=x.display==''?'none':'';\">" + message + "</a>";
......
...@@ -221,9 +221,9 @@ public class RunScript extends Tool { ...@@ -221,9 +221,9 @@ public class RunScript extends Tool {
for (int i = 0; i < columns; i++) { for (int i = 0; i < columns; i++) {
String s = rs.getString(i + 1); String s = rs.getString(i + 1);
if (s != null) { if (s != null) {
s = StringUtils.replaceAll(s, "\r\n", "\n"); s = StringUtils.replaceAll(s, "\r\n", "\n", false);
s = StringUtils.replaceAll(s, "\n", "\n--> "); s = StringUtils.replaceAll(s, "\n", "\n--> ", false);
s = StringUtils.replaceAll(s, "\r", "\r--> "); s = StringUtils.replaceAll(s, "\r", "\r--> ", false);
} }
buff.append(' ').append(s); buff.append(' ').append(s);
} }
...@@ -235,11 +235,11 @@ public class RunScript extends Tool { ...@@ -235,11 +235,11 @@ public class RunScript extends Tool {
} }
if (checkResults) { if (checkResults) {
String expected = r.readStatement() + ";"; String expected = r.readStatement() + ";";
expected = StringUtils.replaceAll(expected, "\r\n", "\n"); expected = StringUtils.replaceAll(expected, "\r\n", "\n", false);
expected = StringUtils.replaceAll(expected, "\r", "\n"); expected = StringUtils.replaceAll(expected, "\r", "\n", false);
if (!expected.equals(result)) { if (!expected.equals(result)) {
expected = StringUtils.replaceAll(expected, " ", "+"); expected = StringUtils.replaceAll(expected, " ", "+", false);
result = StringUtils.replaceAll(result, " ", "+"); result = StringUtils.replaceAll(result, " ", "+", false);
throw new SQLException("Unexpected output for:\n" + sql.trim() + "\nGot:\n" + result + "\nExpected:\n" + expected); throw new SQLException("Unexpected output for:\n" + sql.trim() + "\nGot:\n" + result + "\nExpected:\n" + expected);
} }
} }
......
...@@ -473,7 +473,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler { ...@@ -473,7 +473,7 @@ public class Server extends Tool implements Runnable, ShutdownHandler {
if (browser.indexOf("%url") >= 0) { if (browser.indexOf("%url") >= 0) {
String[] args = StringUtils.arraySplit(browser, ',', false); String[] args = StringUtils.arraySplit(browser, ',', false);
for (int i = 0; i < args.length; i++) { for (int i = 0; i < args.length; i++) {
args[i] = StringUtils.replaceAll(args[i], "%url", url); args[i] = StringUtils.replaceAll(args[i], "%url", url, false);
} }
rt.exec(args); rt.exec(args);
} else if (osName.indexOf("windows") >= 0) { } else if (osName.indexOf("windows") >= 0) {
......
...@@ -17,6 +17,7 @@ import java.util.Properties; ...@@ -17,6 +17,7 @@ import java.util.Properties;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.store.fs.FileSystem; import org.h2.store.fs.FileSystem;
import org.h2.store.fs.FileSystemDisk; import org.h2.store.fs.FileSystemDisk;
import org.h2.util.StringUtils;
import org.h2.util.Utils; import org.h2.util.Utils;
/** /**
...@@ -55,10 +56,10 @@ public class DbUpgrade { ...@@ -55,10 +56,10 @@ public class DbUpgrade {
public static Connection connectWithOldVersion(String url, Properties info) throws SQLException { public static Connection connectWithOldVersion(String url, Properties info) throws SQLException {
try { try {
String oldStartUrlPrefix = (String) Utils.getStaticField("org.h2.upgrade.v1_1.engine.Constants.START_URL"); String oldStartUrlPrefix = (String) Utils.getStaticField("org.h2.upgrade.v1_1.engine.Constants.START_URL");
url = url.replaceAll(org.h2.engine.Constants.START_URL, oldStartUrlPrefix); url = StringUtils.replaceAll(url, org.h2.engine.Constants.START_URL, oldStartUrlPrefix, false);
url = url.replaceAll(";IGNORE_UNKNOWN_SETTINGS=TRUE", ""); url = StringUtils.replaceAll(url, ";IGNORE_UNKNOWN_SETTINGS=TRUE", "", true);
url = url.replaceAll(";IGNORE_UNKNOWN_SETTINGS=FALSE", ""); url = StringUtils.replaceAll(url, ";IGNORE_UNKNOWN_SETTINGS=FALSE", "", true);
url = url.replaceAll(";PAGE_STORE=TRUE", ""); url = StringUtils.replaceAll(url, ";PAGE_STORE=TRUE", "", true);
url += ";IGNORE_UNKNOWN_SETTINGS=TRUE"; url += ";IGNORE_UNKNOWN_SETTINGS=TRUE";
Object ci = Utils.newInstance("org.h2.upgrade.v1_1.engine.ConnectionInfo", url, info); Object ci = Utils.newInstance("org.h2.upgrade.v1_1.engine.ConnectionInfo", url, info);
boolean isRemote = (Boolean) Utils.callMethod(ci, "isRemote"); boolean isRemote = (Boolean) Utils.callMethod(ci, "isRemote");
......
...@@ -16,6 +16,7 @@ import java.util.UUID; ...@@ -16,6 +16,7 @@ import java.util.UUID;
import org.h2.message.DbException; import org.h2.message.DbException;
import org.h2.store.fs.FileSystem; import org.h2.store.fs.FileSystem;
import org.h2.store.fs.FileSystemDisk; import org.h2.store.fs.FileSystemDisk;
import org.h2.util.StringUtils;
import org.h2.util.Utils; import org.h2.util.Utils;
/** /**
...@@ -61,16 +62,17 @@ public class DbUpgradeNonPageStoreToCurrent { ...@@ -61,16 +62,17 @@ public class DbUpgradeNonPageStoreToCurrent {
private void init() throws SQLException { private void init() throws SQLException {
try { try {
newUrl = url; newUrl = url;
newUrl = newUrl.replaceAll(";UNDO_LOG=\\d", ""); newUrl = StringUtils.replaceAll(newUrl, ";UNDO_LOG=1", "", true);
newUrl = StringUtils.replaceAll(newUrl, ";UNDO_LOG=0", "", true);
newUrl += ";UNDO_LOG=0"; newUrl += ";UNDO_LOG=0";
String oldStartUrlPrefix = (String) Utils.getStaticField("org.h2.upgrade.v1_1.engine.Constants.START_URL"); String oldStartUrlPrefix = (String) Utils.getStaticField("org.h2.upgrade.v1_1.engine.Constants.START_URL");
oldUrl = url; oldUrl = url;
oldUrl = oldUrl.replaceAll(org.h2.engine.Constants.START_URL, oldStartUrlPrefix); oldUrl = StringUtils.replaceAll(oldUrl, org.h2.engine.Constants.START_URL, oldStartUrlPrefix, false);
oldUrl = oldUrl.replaceAll(";IGNORE_UNKNOWN_SETTINGS=TRUE", ""); oldUrl = StringUtils.replaceAll(oldUrl, ";IGNORE_UNKNOWN_SETTINGS=TRUE", "", true);
oldUrl = oldUrl.replaceAll(";IGNORE_UNKNOWN_SETTINGS=FALSE", ""); oldUrl = StringUtils.replaceAll(oldUrl, ";IGNORE_UNKNOWN_SETTINGS=FALSE", "", true);
oldUrl = oldUrl.replaceAll(";IFEXISTS=TRUE", ""); oldUrl = StringUtils.replaceAll(oldUrl, ";IFEXISTS=TRUE", "", true);
oldUrl = oldUrl.replaceAll(";IFEXISTS=FALSE", ""); oldUrl = StringUtils.replaceAll(oldUrl, ";IFEXISTS=FALSE", "", true);
oldUrl = oldUrl.replaceAll(";PAGE_STORE=TRUE", ""); oldUrl = StringUtils.replaceAll(oldUrl, ";PAGE_STORE=TRUE", "", true);
oldUrl += ";IGNORE_UNKNOWN_SETTINGS=TRUE"; oldUrl += ";IGNORE_UNKNOWN_SETTINGS=TRUE";
Object ci = Utils.newInstance("org.h2.upgrade.v1_1.engine.ConnectionInfo", oldUrl, info); Object ci = Utils.newInstance("org.h2.upgrade.v1_1.engine.ConnectionInfo", oldUrl, info);
boolean isRemote = (Boolean) Utils.callMethod(ci, "isRemote"); boolean isRemote = (Boolean) Utils.callMethod(ci, "isRemote");
......
...@@ -146,7 +146,7 @@ public class JdbcUtils { ...@@ -146,7 +146,7 @@ public class JdbcUtils {
if (pattern == null || pattern.length() == 0) { if (pattern == null || pattern.length() == 0) {
return pattern; return pattern;
} }
return StringUtils.replaceAll(pattern, "\\", "\\\\"); return StringUtils.replaceAll(pattern, "\\", "\\\\", false);
} }
/** /**
......
...@@ -210,7 +210,7 @@ public class SourceCompiler { ...@@ -210,7 +210,7 @@ public class SourceCompiler {
private void throwSyntaxError(ByteArrayOutputStream out) { private void throwSyntaxError(ByteArrayOutputStream out) {
String err = StringUtils.utf8Decode(out.toByteArray()); String err = StringUtils.utf8Decode(out.toByteArray());
if (err.length() > 0) { if (err.length() > 0) {
err = StringUtils.replaceAll(err, compileDir, ""); err = StringUtils.replaceAll(err, compileDir, "", false);
throw DbException.get(ErrorCode.SYNTAX_ERROR_1, err); throw DbException.get(ErrorCode.SYNTAX_ERROR_1, err);
} }
} }
......
...@@ -697,10 +697,18 @@ public class StringUtils { ...@@ -697,10 +697,18 @@ public class StringUtils {
* @param s the string * @param s the string
* @param before the old text * @param before the old text
* @param after the new text * @param after the new text
* @param caseInsensitive true if it should be case insensitive
* @return the string with the before string replaced * @return the string with the before string replaced
*/ */
public static String replaceAll(String s, String before, String after) { public static String replaceAll(String s, String before, String after, boolean caseInsensitive) {
int next = s.indexOf(before); String testString;
if (caseInsensitive) {
testString = s.toLowerCase(Locale.ENGLISH);
before = before.toLowerCase(Locale.ENGLISH);
} else {
testString = s;
}
int next = testString.indexOf(before);
if (next < 0) { if (next < 0) {
return s; return s;
} }
...@@ -709,7 +717,7 @@ public class StringUtils { ...@@ -709,7 +717,7 @@ public class StringUtils {
while (true) { while (true) {
buff.append(s.substring(index, next)).append(after); buff.append(s.substring(index, next)).append(after);
index = next + before.length(); index = next + before.length();
next = s.indexOf(before, index); next = testString.indexOf(before, index);
if (next < 0) { if (next < 0) {
buff.append(s.substring(index)); buff.append(s.substring(index));
break; break;
...@@ -755,8 +763,8 @@ public class StringUtils { ...@@ -755,8 +763,8 @@ public class StringUtils {
* @return the resulting string * @return the resulting string
*/ */
public static String quoteRemarkSQL(String sql) { public static String quoteRemarkSQL(String sql) {
sql = replaceAll(sql, "*/", "++/"); sql = replaceAll(sql, "*/", "++/", false);
return replaceAll(sql, "/*", "/++"); return replaceAll(sql, "/*", "/++", false);
} }
/** /**
......
...@@ -63,18 +63,18 @@ public class Newsfeed { ...@@ -63,18 +63,18 @@ public class Newsfeed {
*/ */
private static String convertHtml2Text(String html) { private static String convertHtml2Text(String html) {
String s = html; String s = html;
s = StringUtils.replaceAll(s, "<b>", ""); s = StringUtils.replaceAll(s, "<b>", "", false);
s = StringUtils.replaceAll(s, "</b>", ""); s = StringUtils.replaceAll(s, "</b>", "", false);
s = StringUtils.replaceAll(s, "<ul>", ""); s = StringUtils.replaceAll(s, "<ul>", "", false);
s = StringUtils.replaceAll(s, "</ul>", ""); s = StringUtils.replaceAll(s, "</ul>", "", false);
s = StringUtils.replaceAll(s, "<li>", "- "); s = StringUtils.replaceAll(s, "<li>", "- ", false);
s = StringUtils.replaceAll(s, "</li>", ""); s = StringUtils.replaceAll(s, "</li>", "", false);
s = StringUtils.replaceAll(s, "<a href=\"", "( "); s = StringUtils.replaceAll(s, "<a href=\"", "( ", false);
s = StringUtils.replaceAll(s, "\">", " ) "); s = StringUtils.replaceAll(s, "\">", " ) ", false);
s = StringUtils.replaceAll(s, "</a>", ""); s = StringUtils.replaceAll(s, "</a>", "", false);
s = StringUtils.replaceAll(s, "<br />", ""); s = StringUtils.replaceAll(s, "<br />", "", false);
s = StringUtils.replaceAll(s, "<br/>", ""); s = StringUtils.replaceAll(s, "<br/>", "", false);
s = StringUtils.replaceAll(s, "<br>", ""); s = StringUtils.replaceAll(s, "<br>", "", false);
if (s.indexOf('<') >= 0 || s.indexOf('>') >= 0) { if (s.indexOf('<') >= 0 || s.indexOf('>') >= 0) {
throw new RuntimeException("Unsupported HTML Tag: < or > in " + s); throw new RuntimeException("Unsupported HTML Tag: < or > in " + s);
} }
......
...@@ -247,7 +247,7 @@ class Database { ...@@ -247,7 +247,7 @@ class Database {
String key = (String) k; String key = (String) k;
if (key.startsWith(databaseType + ".")) { if (key.startsWith(databaseType + ".")) {
String pattern = key.substring(databaseType.length() + 1); String pattern = key.substring(databaseType.length() + 1);
pattern = StringUtils.replaceAll(pattern, "_", " "); pattern = StringUtils.replaceAll(pattern, "_", " ", false);
pattern = StringUtils.toUpperEnglish(pattern); pattern = StringUtils.toUpperEnglish(pattern);
String replacement = prop.getProperty(key); String replacement = prop.getProperty(key);
replace.add(new String[]{pattern, replacement}); replace.add(new String[]{pattern, replacement});
...@@ -270,7 +270,7 @@ class Database { ...@@ -270,7 +270,7 @@ class Database {
for (String[] pair : replace) { for (String[] pair : replace) {
String pattern = pair[0]; String pattern = pair[0];
String replacement = pair[1]; String replacement = pair[1];
sql = StringUtils.replaceAll(sql, pattern, replacement); sql = StringUtils.replaceAll(sql, pattern, replacement, false);
} }
return sql; return sql;
} }
......
...@@ -208,7 +208,7 @@ public class TestCsv extends TestBase { ...@@ -208,7 +208,7 @@ public class TestCsv extends TestBase {
stat.execute("call csvwrite('"+fileName+"', 'select 1 id, ''Hello'' name', null, '|', '', null, null, chr(10))"); stat.execute("call csvwrite('"+fileName+"', 'select 1 id, ''Hello'' name', null, '|', '', null, null, chr(10))");
InputStreamReader reader = new InputStreamReader(IOUtils.openFileInputStream(fileName)); InputStreamReader reader = new InputStreamReader(IOUtils.openFileInputStream(fileName));
String text = IOUtils.readStringAndClose(reader, -1).trim(); String text = IOUtils.readStringAndClose(reader, -1).trim();
text = StringUtils.replaceAll(text, "\n", " "); text = StringUtils.replaceAll(text, "\n", " ", false);
assertEquals("ID|NAME 1|Hello", text); assertEquals("ID|NAME 1|Hello", text);
ResultSet rs = stat.executeQuery("select * from csvread('" + fileName + "', null, null, '|', '')"); ResultSet rs = stat.executeQuery("select * from csvread('" + fileName + "', null, null, '|', '')");
ResultSetMetaData meta = rs.getMetaData(); ResultSetMetaData meta = rs.getMetaData();
......
...@@ -92,7 +92,7 @@ public class TestSampleApps extends TestBase { ...@@ -92,7 +92,7 @@ public class TestSampleApps extends TestBase {
System.setOut(oldOut); System.setOut(oldOut);
System.setErr(oldErr); System.setErr(oldErr);
String s = new String(buff.toByteArray(), "UTF-8"); String s = new String(buff.toByteArray(), "UTF-8");
s = StringUtils.replaceAll(s, "\r\n", "\n"); s = StringUtils.replaceAll(s, "\r\n", "\n", false);
s = s.trim(); s = s.trim();
expected = expected.trim(); expected = expected.trim();
if (expected.endsWith("*")) { if (expected.endsWith("*")) {
......
...@@ -37,6 +37,7 @@ public class TestStringUtils extends TestBase { ...@@ -37,6 +37,7 @@ public class TestStringUtils extends TestBase {
testJavaString(); testJavaString();
testURL(); testURL();
testPad(); testPad();
testReplaceAll();
} }
private void testHex() { private void testHex() {
...@@ -167,4 +168,20 @@ public class TestStringUtils extends TestBase { ...@@ -167,4 +168,20 @@ public class TestStringUtils extends TestBase {
} }
} }
private void testReplaceAll() {
assertEquals("def", StringUtils.replaceAll("abc def", "abc ", "", false));
assertEquals("adef", StringUtils.replaceAll("abc def", "bc ", "", false));
assertEquals("abc def", StringUtils.replaceAll("abc def", "bc ", "bc ", false));
assertEquals("abc ", StringUtils.replaceAll("abc def", "def", "", false));
assertEquals(" ", StringUtils.replaceAll("abc abc", "abc", "", false));
assertEquals("xyz xyz", StringUtils.replaceAll("abc abc", "abc", "xyz", false));
assertEquals("abc def", StringUtils.replaceAll("abc def", "xyz", "abc", false));
assertEquals("", StringUtils.replaceAll("abcabcabc", "abc", "", false));
assertEquals("abcabcabc", StringUtils.replaceAll("abcabcabc", "aBc", "", false));
assertEquals("X", StringUtils.replaceAll("Xabcabcabc", "aBc", "", true));
assertEquals("X", StringUtils.replaceAll("XaBcabcaBc", "abc", "", true));
assertEquals("x", StringUtils.replaceAll("xabcabcabc", "aBc", "", true));
assertEquals("x", StringUtils.replaceAll("xaBcabcaBc", "abc", "", true));
}
} }
...@@ -34,12 +34,12 @@ public class BnfRailroad implements BnfVisitor { ...@@ -34,12 +34,12 @@ public class BnfRailroad implements BnfVisitor {
public String getHtml(Bnf bnf, String syntaxLines) { public String getHtml(Bnf bnf, String syntaxLines) {
syntaxVisitor = new BnfSyntax(); syntaxVisitor = new BnfSyntax();
this.config = bnf; this.config = bnf;
syntaxLines = StringUtils.replaceAll(syntaxLines, "\n ", " "); syntaxLines = StringUtils.replaceAll(syntaxLines, "\n ", " ", false);
String[] syntaxList = StringUtils.arraySplit(syntaxLines, '\n', true); String[] syntaxList = StringUtils.arraySplit(syntaxLines, '\n', true);
StringBuilder buff = new StringBuilder(); StringBuilder buff = new StringBuilder();
for (String s : syntaxList) { for (String s : syntaxList) {
bnf.visit(this, s); bnf.visit(this, s);
html = StringUtils.replaceAll(html, "</code></td><td class=\"d\"><code class=\"c\">", " "); html = StringUtils.replaceAll(html, "</code></td><td class=\"d\"><code class=\"c\">", " ", false);
if (buff.length() > 0) { if (buff.length() > 0) {
buff.append("<br />"); buff.append("<br />");
} }
......
...@@ -30,7 +30,7 @@ public class BnfSyntax implements BnfVisitor { ...@@ -30,7 +30,7 @@ public class BnfSyntax implements BnfVisitor {
* @return the HTML * @return the HTML
*/ */
public String getHtml(Bnf bnf, String syntaxLines) { public String getHtml(Bnf bnf, String syntaxLines) {
syntaxLines = StringUtils.replaceAll(syntaxLines, "\n ", "\n"); syntaxLines = StringUtils.replaceAll(syntaxLines, "\n ", "\n", false);
StringTokenizer tokenizer = bnf.getTokenizer(syntaxLines); StringTokenizer tokenizer = bnf.getTokenizer(syntaxLines);
StringBuilder buff = new StringBuilder(); StringBuilder buff = new StringBuilder();
while (tokenizer.hasMoreTokens()) { while (tokenizer.hasMoreTokens()) {
...@@ -43,7 +43,7 @@ public class BnfSyntax implements BnfVisitor { ...@@ -43,7 +43,7 @@ public class BnfSyntax implements BnfVisitor {
} }
String s = buff.toString(); String s = buff.toString();
// ensure it works within XHTML comments // ensure it works within XHTML comments
s = StringUtils.replaceAll(s, "--", "&#45;-"); s = StringUtils.replaceAll(s, "--", "&#45;-", false);
return s; return s;
} }
......
...@@ -149,15 +149,15 @@ public class GenerateDoc { ...@@ -149,15 +149,15 @@ public class GenerateDoc {
String text = map.get("text"); String text = map.get("text");
if (text != null) { if (text != null) {
// text is enclosed in <p> .. </p> so this works. // text is enclosed in <p> .. </p> so this works.
text = StringUtils.replaceAll(text, "<br /><br />", "</p><p>"); text = StringUtils.replaceAll(text, "<br /><br />", "</p><p>", false);
text = StringUtils.replaceAll(text, "<br />", " "); text = StringUtils.replaceAll(text, "<br />", " ", false);
map.put("text", text); map.put("text", text);
} }
String link = topic.toLowerCase(); String link = topic.toLowerCase();
link = StringUtils.replaceAll(link, " ", "_"); link = StringUtils.replaceAll(link, " ", "_", false);
// link = StringUtils.replaceAll(link, "_", ""); // link = StringUtils.replaceAll(link, "_", "");
link = StringUtils.replaceAll(link, "@", "_"); link = StringUtils.replaceAll(link, "@", "_", false);
map.put("link", StringUtils.urlEncode(link)); map.put("link", StringUtils.urlEncode(link));
list.add(map); list.add(map);
......
...@@ -41,7 +41,7 @@ public class MergeDocs { ...@@ -41,7 +41,7 @@ public class MergeDocs {
for (String fileName : pages) { for (String fileName : pages) {
String text = getContent(fileName); String text = getContent(fileName);
for (String page : pages) { for (String page : pages) {
text = StringUtils.replaceAll(text, page + "#", "#"); text = StringUtils.replaceAll(text, page + "#", "#", false);
} }
text = disableRailroads(text); text = disableRailroads(text);
text = removeHeaderFooter(fileName, text); text = removeHeaderFooter(fileName, text);
...@@ -61,10 +61,10 @@ public class MergeDocs { ...@@ -61,10 +61,10 @@ public class MergeDocs {
} }
private String disableRailroads(String text) { private String disableRailroads(String text) {
text = StringUtils.replaceAll(text, "<!-- railroad-start -->", "<!-- railroad-start "); text = StringUtils.replaceAll(text, "<!-- railroad-start -->", "<!-- railroad-start ", false);
text = StringUtils.replaceAll(text, "<!-- railroad-end -->", " railroad-end -->"); text = StringUtils.replaceAll(text, "<!-- railroad-end -->", " railroad-end -->", false);
text = StringUtils.replaceAll(text, "<!-- syntax-start", "<!-- syntax-start -->"); text = StringUtils.replaceAll(text, "<!-- syntax-start", "<!-- syntax-start -->", false);
text = StringUtils.replaceAll(text, "syntax-end -->", "<!-- syntax-end -->"); text = StringUtils.replaceAll(text, "syntax-end -->", "<!-- syntax-end -->", false);
return text; return text;
} }
......
...@@ -175,7 +175,7 @@ public class SpellChecker { ...@@ -175,7 +175,7 @@ public class SpellChecker {
StringBuilder buff = new StringBuilder(text.length()); StringBuilder buff = new StringBuilder(text.length());
int pos = 0, last = 0; int pos = 0, last = 0;
if (fileName.endsWith(".properties")) { if (fileName.endsWith(".properties")) {
text = StringUtils.replaceAll(text, "\\:", ":"); text = StringUtils.replaceAll(text, "\\:", ":", false);
} }
while (true) { while (true) {
pos = text.indexOf("http://", pos); pos = text.indexOf("http://", pos);
......
...@@ -55,8 +55,8 @@ public class UploadBuild { ...@@ -55,8 +55,8 @@ public class UploadBuild {
idx = index.indexOf("</A>"); idx = index.indexOf("</A>");
index = index.substring(0, idx) + index.substring(idx + "</A>".length()); index = index.substring(0, idx) + index.substring(idx + "</A>".length());
} }
index = StringUtils.replaceAll(index, "[all", ""); index = StringUtils.replaceAll(index, "[all", "", false);
index = StringUtils.replaceAll(index, "classes]", ""); index = StringUtils.replaceAll(index, "classes]", "", false);
FileOutputStream out = new FileOutputStream("coverage/overview.html"); FileOutputStream out = new FileOutputStream("coverage/overview.html");
out.write(index.getBytes("ISO-8859-1")); out.write(index.getBytes("ISO-8859-1"));
out.close(); out.close();
......
...@@ -138,18 +138,18 @@ public class WebSite { ...@@ -138,18 +138,18 @@ public class WebSite {
if (name.endsWith(".html")) { if (name.endsWith(".html")) {
String page = new String(bytes, "UTF-8"); String page = new String(bytes, "UTF-8");
if (web) { if (web) {
page = StringUtils.replaceAll(page, ANALYTICS_TAG, ANALYTICS_SCRIPT); page = StringUtils.replaceAll(page, ANALYTICS_TAG, ANALYTICS_SCRIPT, false);
} }
if (replaceFragments) { if (replaceFragments) {
page = replaceFragments(name, page); page = replaceFragments(name, page);
page = StringUtils.replaceAll(page, "<a href=\"frame", "<a href=\"main"); page = StringUtils.replaceAll(page, "<a href=\"frame", "<a href=\"main", false);
page = StringUtils.replaceAll(page, "html/frame.html", "html/main.html"); page = StringUtils.replaceAll(page, "html/frame.html", "html/main.html", false);
} }
if (web) { if (web) {
page = StringUtils.replaceAll(page, TRANSLATE_START, ""); page = StringUtils.replaceAll(page, TRANSLATE_START, "", false);
page = StringUtils.replaceAll(page, TRANSLATE_END, ""); page = StringUtils.replaceAll(page, TRANSLATE_END, "", false);
page = StringUtils.replaceAll(page, "<pre>", "<pre class=\"notranslate\">"); page = StringUtils.replaceAll(page, "<pre>", "<pre class=\"notranslate\">", false);
page = StringUtils.replaceAll(page, "<code>", "<code class=\"notranslate\">"); page = StringUtils.replaceAll(page, "<code>", "<code class=\"notranslate\">", false);
} }
bytes = page.getBytes("UTF-8"); bytes = page.getBytes("UTF-8");
} }
......
...@@ -153,7 +153,7 @@ public class Doclet { ...@@ -153,7 +153,7 @@ public class Doclet {
boolean isVarArgs = method.isVarArgs() && j == params.length - 1; boolean isVarArgs = method.isVarArgs() && j == params.length - 1;
String typeName = getTypeName(false, isVarArgs, param.type()); String typeName = getTypeName(false, isVarArgs, param.type());
buff.append(typeName); buff.append(typeName);
buffSignature.append(StringUtils.replaceAll(typeName, "[]", "-")); buffSignature.append(StringUtils.replaceAll(typeName, "[]", "-", false));
buff.append(' '); buff.append(' ');
buff.append(param.name()); buff.append(param.name());
} }
...@@ -380,7 +380,7 @@ public class Doclet { ...@@ -380,7 +380,7 @@ public class Doclet {
if (text == null) { if (text == null) {
return text; return text;
} }
text = StringUtils.replaceAll(text, "\n </pre>", "</pre>"); text = StringUtils.replaceAll(text, "\n </pre>", "</pre>", false);
return text; return text;
} }
......
...@@ -129,16 +129,16 @@ public class PrepareTranslation { ...@@ -129,16 +129,16 @@ public class PrepareTranslation {
map.put(k.toString(), prop.get(k)); map.put(k.toString(), prop.get(k));
} }
String html = PageParser.parse(template, map); String html = PageParser.parse(template, map);
html = StringUtils.replaceAll(html, "lang=\"" + MAIN_LANGUAGE + "\"", "lang=\"" + language + "\""); html = StringUtils.replaceAll(html, "lang=\"" + MAIN_LANGUAGE + "\"", "lang=\"" + language + "\"", false);
for (String n : fileNames) { for (String n : fileNames) {
if ("frame".equals(n)) { if ("frame".equals(n)) {
// don't translate 'frame.html' to 'frame_ja.html', // don't translate 'frame.html' to 'frame_ja.html',
// otherwise we can't switch back to English // otherwise we can't switch back to English
continue; continue;
} }
html = StringUtils.replaceAll(html, n + ".html\"", n + "_" + language + ".html\""); html = StringUtils.replaceAll(html, n + ".html\"", n + "_" + language + ".html\"", false);
} }
html = StringUtils.replaceAll(html, "_" + MAIN_LANGUAGE + ".html\"", ".html\""); html = StringUtils.replaceAll(html, "_" + MAIN_LANGUAGE + ".html\"", ".html\"", false);
String target; String target;
if (language.equals(MAIN_LANGUAGE)) { if (language.equals(MAIN_LANGUAGE)) {
target = targetDir + "/" + name + ".html"; target = targetDir + "/" + name + ".html";
...@@ -376,7 +376,7 @@ public class PrepareTranslation { ...@@ -376,7 +376,7 @@ public class PrepareTranslation {
text = text.replace('\r', ' '); text = text.replace('\r', ' ');
text = text.replace('\n', ' '); text = text.replace('\n', ' ');
while (true) { while (true) {
String s = StringUtils.replaceAll(text, " ", " "); String s = StringUtils.replaceAll(text, " ", " ", false);
if (s.equals(text)) { if (s.equals(text)) {
break; break;
} }
......
...@@ -146,8 +146,8 @@ public class PropertiesToUTF8 { ...@@ -146,8 +146,8 @@ public class PropertiesToUTF8 {
out.close(); out.close();
} }
String java = StringUtils.javaEncode(utf8); String java = StringUtils.javaEncode(utf8);
java = StringUtils.replaceAll(java, "\\r", "\r"); java = StringUtils.replaceAll(java, "\\r", "\r", false);
java = StringUtils.replaceAll(java, "\\n", "\n"); java = StringUtils.replaceAll(java, "\\n", "\n", false);
RandomAccessFile out = new RandomAccessFile("_java." + name, "rw"); RandomAccessFile out = new RandomAccessFile("_java." + name, "rw");
out.write(java.getBytes()); out.write(java.getBytes());
out.setLength(out.getFilePointer()); out.setLength(out.getFilePointer());
......
...@@ -447,7 +447,7 @@ public class FtpClient { ...@@ -447,7 +447,7 @@ public class FtpClient {
for (int i = 0; i < files.length; i++) { for (int i = 0; i < files.length; i++) {
String s = list[i]; String s = list[i];
while (true) { while (true) {
String s2 = StringUtils.replaceAll(s, " ", " "); String s2 = StringUtils.replaceAll(s, " ", " ", false);
if (s2.equals(s)) { if (s2.equals(s)) {
break; break;
} }
......
...@@ -101,15 +101,15 @@ public class Railroads { ...@@ -101,15 +101,15 @@ public class Railroads {
String text = map.get("text"); String text = map.get("text");
if (text != null) { if (text != null) {
// text is enclosed in <p> .. </p> so this works. // text is enclosed in <p> .. </p> so this works.
text = StringUtils.replaceAll(text, "<br /><br />", "</p><p>"); text = StringUtils.replaceAll(text, "<br /><br />", "</p><p>", false);
text = StringUtils.replaceAll(text, "<br />", " "); text = StringUtils.replaceAll(text, "<br />", " ", false);
map.put("text", text); map.put("text", text);
} }
String link = topic.toLowerCase(); String link = topic.toLowerCase();
link = StringUtils.replaceAll(link, " ", "_"); link = StringUtils.replaceAll(link, " ", "_", false);
// link = StringUtils.replaceAll(link, "_", ""); // link = StringUtils.replaceAll(link, "_", "");
link = StringUtils.replaceAll(link, "@", "_"); link = StringUtils.replaceAll(link, "@", "_", false);
map.put("link", StringUtils.urlEncode(link)); map.put("link", StringUtils.urlEncode(link));
list.add(map); list.add(map);
} }
......
...@@ -134,7 +134,7 @@ public class FunctionsMySQL { ...@@ -134,7 +134,7 @@ public class FunctionsMySQL {
private static String convertToSimpleDateFormat(String format) { private static String convertToSimpleDateFormat(String format) {
String[] replace = FORMAT_REPLACE; String[] replace = FORMAT_REPLACE;
for (int i = 0; i < replace.length; i += 2) { for (int i = 0; i < replace.length; i += 2) {
format = StringUtils.replaceAll(format, replace[i], replace[i + 1]); format = StringUtils.replaceAll(format, replace[i], replace[i + 1], false);
} }
return format; return format;
} }
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论