From 37fdbdef97d2756d46e0d0538987df930d3b0b22 Mon Sep 17 00:00:00 2001 From: Niki Roo Date: Wed, 12 Jul 2017 22:36:14 +0200 Subject: [PATCH] FimfictionAPI: quote problem in json "parsing" --- .../fanfix/supported/FimfictionApi.java | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/be/nikiroo/fanfix/supported/FimfictionApi.java b/src/be/nikiroo/fanfix/supported/FimfictionApi.java index 591bbb08..1594d5e1 100644 --- a/src/be/nikiroo/fanfix/supported/FimfictionApi.java +++ b/src/be/nikiroo/fanfix/supported/FimfictionApi.java @@ -281,6 +281,34 @@ class FimfictionApi extends BasicSupport { return null; } - return getKeyText(json.substring(pos), "\"", null, "\""); + String result = null; + String wip = json.substring(pos); + + pos = nextUnescapedQuote(wip, 0); + if (pos >= 0) { + wip = wip.substring(pos + 1); + pos = nextUnescapedQuote(wip, 0); + if (pos >= 0) { + result = wip.substring(0, pos); + } + } + + return result; + } + + // next " but don't take \" into account + static private int nextUnescapedQuote(String result, int pos) { + while (pos >= 0) { + pos = result.indexOf("\"", pos); + if (pos == 0 || (pos > 0 && result.charAt(pos - 1) != '\\')) { + break; + } + + if (pos < result.length()) { + pos++; + } + } + + return pos; } } -- 2.27.0