Skip to content

Commit 931978f

Browse files
CopilotNotMyFault
andauthored
Handle braces inside JSON strings
Co-authored-by: NotMyFault <13383509+NotMyFault@users.noreply.github.com>
1 parent 7e8b28c commit 931978f

1 file changed

Lines changed: 22 additions & 25 deletions

File tree

src/main/java/com/thevoxelbox/voxelsniper/VoxelSniperPlugin.java

Lines changed: 22 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,28 @@ private static String findLatestVersionName(String response) {
339339
int objectDepth = 0;
340340
for (int index = 0; index < lastObject.length(); index++) {
341341
char character = lastObject.charAt(index);
342+
if (character == '"') {
343+
int stringEnd = findStringEnd(lastObject, index + 1);
344+
if (stringEnd == -1) {
345+
return null;
346+
}
347+
if (objectDepth == 1) {
348+
String key = lastObject.substring(index + 1, stringEnd);
349+
int colonIndex = skipWhitespace(lastObject, stringEnd + 1);
350+
if (colonIndex < lastObject.length() && lastObject.charAt(colonIndex) == ':') {
351+
int valueStart = skipWhitespace(lastObject, colonIndex + 1);
352+
if ("name".equals(key) && valueStart < lastObject.length() && lastObject.charAt(valueStart) == '"') {
353+
int valueEnd = findStringEnd(lastObject, valueStart + 1);
354+
if (valueEnd == -1) {
355+
return null;
356+
}
357+
return lastObject.substring(valueStart + 1, valueEnd);
358+
}
359+
}
360+
}
361+
index = stringEnd;
362+
continue;
363+
}
342364
if (character == '{') {
343365
objectDepth++;
344366
continue;
@@ -347,31 +369,6 @@ private static String findLatestVersionName(String response) {
347369
objectDepth--;
348370
continue;
349371
}
350-
if (objectDepth != 1 || character != '"') {
351-
continue;
352-
}
353-
354-
int keyEnd = findStringEnd(lastObject, index + 1);
355-
if (keyEnd == -1) {
356-
return null;
357-
}
358-
String key = lastObject.substring(index + 1, keyEnd);
359-
int colonIndex = skipWhitespace(lastObject, keyEnd + 1);
360-
if (colonIndex >= lastObject.length() || lastObject.charAt(colonIndex) != ':') {
361-
index = keyEnd;
362-
continue;
363-
}
364-
int valueStart = skipWhitespace(lastObject, colonIndex + 1);
365-
if (!"name".equals(key) || valueStart >= lastObject.length() || lastObject.charAt(valueStart) != '"') {
366-
index = keyEnd;
367-
continue;
368-
}
369-
370-
int valueEnd = findStringEnd(lastObject, valueStart + 1);
371-
if (valueEnd == -1) {
372-
return null;
373-
}
374-
return lastObject.substring(valueStart + 1, valueEnd);
375372
}
376373
return null;
377374
}

0 commit comments

Comments
 (0)