summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-02-17 19:21:37 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-02-19 14:51:04 -0700
commit49ee8be679add0bd3cf08a2669331b3be7a835f8 (patch)
treeb3d3f889ed25084fe33ed9e01554d6ca51104bb5 /internal
parent00187950437a10952b82353405e5ba4b4515fb29 (diff)
compat/json: Correctly handle syntax-error-in-decode
Diffstat (limited to 'internal')
-rw-r--r--internal/jsonparse/parse.go15
1 files changed, 15 insertions, 0 deletions
diff --git a/internal/jsonparse/parse.go b/internal/jsonparse/parse.go
index 1c35533..6432d75 100644
--- a/internal/jsonparse/parse.go
+++ b/internal/jsonparse/parse.go
@@ -525,6 +525,21 @@ func (par *Parser) HandleEOF() (RuneType, error) {
}
}
+// IsAtBarrier returns whether a read-barrier has been reached and the
+// next HandleRune call would definitely return RuneTypeEOF.
+func (par *Parser) IsAtBarrier() bool {
+ return par.initialized &&
+ // HandleRune wouldn't return early with an error.
+ !par.closed &&
+ par.err == nil &&
+ // The current (sub-)parser has reached its end, and
+ len(par.stack) == 0 &&
+ // there is a barrier, and
+ len(par.barriers) > 0 &&
+ // that barrier would definitely return RuneTypeEOF.
+ !par.barriers[len(par.barriers)-1].allowWS
+}
+
// HandleRune feeds a Unicode rune to the Parser.
//
// An error is returned if and only if the RuneType is RuneTypeError.