Fix string quoter not handling it properly
This commit is contained in:
		| @@ -1633,8 +1633,7 @@ public class DisguiseUtilities { | |||||||
|             return string; |             return string; | ||||||
|         } |         } | ||||||
|  |  | ||||||
|         return "\"" + string.replaceAll("\\B\"", "\\\"").replaceAll("\\\\(?=\\\\*\"\\B)", "\\\\") |         return "\"" + string.replaceAll("\\\\(?=\\\\*\"( |$))", "\\\\\\\\").replaceAll("((?<= )\")|(\"(?= ))", "\\\\\"") + "\""; | ||||||
|                 .replaceAll("(?=\"\\B)", "\\") + "\""; |  | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     public static String[] split(String string) { |     public static String[] split(String string) { | ||||||
|   | |||||||
| @@ -1,5 +1,7 @@ | |||||||
| package me.libraryaddict.disguise.utilities; | package me.libraryaddict.disguise.utilities; | ||||||
|  |  | ||||||
|  | import com.google.gson.Gson; | ||||||
|  | import org.apache.commons.lang.StringUtils; | ||||||
| import org.junit.Assert; | import org.junit.Assert; | ||||||
| import org.junit.Test; | import org.junit.Test; | ||||||
|  |  | ||||||
| @@ -108,6 +110,21 @@ public class DisguiseUtilitiesTest { | |||||||
|  |  | ||||||
|                 "Foobar", "is", "not", "Foo Bar", "but", "is", "a", "single", "word", "foobar", "or", "as", "some", |                 "Foobar", "is", "not", "Foo Bar", "but", "is", "a", "single", "word", "foobar", "or", "as", "some", | ||||||
|                 "quote", "it,", "'foobar'", "and", "again,", "not", "'foo", "bar'", "-", "It", "is", "'foobar'!"); |                 "quote", "it,", "'foobar'", "and", "again,", "not", "'foo", "bar'", "-", "It", "is", "'foobar'!"); | ||||||
|  |  | ||||||
|  |         splitAndBack("Hi \" bye"); | ||||||
|  |         splitAndBack("Hi\\\" I'm Sam"); | ||||||
|  |         splitAndBack("\"Hi\\\" I'm Sam"); | ||||||
|  |         splitAndBack("\"Hi\\\\\" I'm Sam"); | ||||||
|  |         splitAndBack("\"Hi\\\\\\\" I'm Sam"); | ||||||
|  |         splitAndBack("\"Hi\\\\\\\" \"I'm Sam"); | ||||||
|  |     } | ||||||
|  |  | ||||||
|  |     private void splitAndBack(String string) { | ||||||
|  |         String quoted = DisguiseUtilities.quote(string); | ||||||
|  |         String[] split = DisguiseUtilities.split(quoted); | ||||||
|  |  | ||||||
|  |         Assert.assertEquals(1, split.length); | ||||||
|  |         Assert.assertEquals(string, split[0]); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     private void splitEquals(String toSplit, String... expected) { |     private void splitEquals(String toSplit, String... expected) { | ||||||
| @@ -116,5 +133,7 @@ public class DisguiseUtilitiesTest { | |||||||
|                 .toArray(String[]::new); |                 .toArray(String[]::new); | ||||||
|  |  | ||||||
|         Assert.assertArrayEquals(expect, splitted); |         Assert.assertArrayEquals(expect, splitted); | ||||||
|  |  | ||||||
|  |         splitAndBack(toSplit); | ||||||
|     } |     } | ||||||
| } | } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user