Skip to content

Commit cadd8dd

Browse files
author
nshkrdotcom
committed
fix dialyzer
1 parent 1c81f08 commit cadd8dd

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

lib/json_remedy/utils/multiple_json_detector.ex

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ defmodule JsonRemedy.Utils.MultipleJsonDetector do
8787
first_char in ["t", "f", "n"] ->
8888
find_literal_end(json_string)
8989

90-
first_char && first_char =~ ~r/[0-9-]/ ->
90+
is_binary(first_char) and String.match?(first_char, ~r/^[0-9-]/) ->
9191
find_number_end(json_string)
9292

9393
true ->
@@ -114,11 +114,14 @@ defmodule JsonRemedy.Utils.MultipleJsonDetector do
114114

115115
defp do_find_matching_delimiter(str, pos, brace_count, bracket_count, in_string, opener) do
116116
char = String.at(str, pos)
117-
prev_char = if pos > 0, do: String.at(str, pos - 1), else: nil
117+
118+
# Check if current character is an unescaped quote
119+
is_unescaped_quote =
120+
char == "\"" and (pos <= 1 or String.at(str, pos - 1) != "\\")
118121

119122
{new_in_string, new_brace, new_bracket} =
120123
cond do
121-
char == "\"" and prev_char != "\\" ->
124+
is_unescaped_quote ->
122125
{!in_string, brace_count, bracket_count}
123126

124127
!in_string and char == "{" ->
@@ -166,10 +169,6 @@ defmodule JsonRemedy.Utils.MultipleJsonDetector do
166169
char = String.at(str, pos)
167170

168171
cond do
169-
is_nil(char) ->
170-
# Reached end of string without finding closing quote
171-
{:ok, str, ""}
172-
173172
escaped ->
174173
find_string_end(str, pos + 1, false)
175174

0 commit comments

Comments
 (0)