json_mend 0.3.3 → 0.3.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/json_mend/parser.rb +9 -19
- data/lib/json_mend/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cf7c2d2fd3815321d7d80912e4ee200cb94a0399220c17219a02f55305f6eccb
|
|
4
|
+
data.tar.gz: 896e1c154c05ce80032072e33d75ddf86335212b0659b9dac93c9c31959da634
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 54571b75e4f4448f8c3d87ff2ac2a9d569f5a75e602845ccbc3dda7ff00a935dd8cc2263c18e557e2ffc59ded871467867b0b1fd0371198d05fbaa6f7df46453
|
|
7
|
+
data.tar.gz: 0f0ef4172ffcbeeb0c28220d6af20603c4fdc7917e833dd2bd111343ec257040767d9a9d21d28d416e8a5096cdfda9baf39a63bf7612ff6cf3b7fb332e8036e2
|
data/lib/json_mend/parser.rb
CHANGED
|
@@ -390,9 +390,6 @@ module JsonMend
|
|
|
390
390
|
# Handle JSON_STOP_TOKEN from parse_json (EOS or consumed terminator)
|
|
391
391
|
if value == JSON_STOP_TOKEN
|
|
392
392
|
# Do nothing, just skipped garbage
|
|
393
|
-
elsif strictly_empty?(value)
|
|
394
|
-
# Only consume if we didn't just hit a terminator that parse_json successfully respected
|
|
395
|
-
@scanner.getch unless value.nil? && TERMINATORS_ARRAY.include?(peek_char)
|
|
396
393
|
elsif value == '...' && @scanner.string.getbyte(@scanner.pos - 1) == 46
|
|
397
394
|
# just skip if the previous byte was a dot (46)
|
|
398
395
|
else
|
|
@@ -1111,18 +1108,21 @@ module JsonMend
|
|
|
1111
1108
|
# Save the original length so we can safely roll back if it's completely invalid
|
|
1112
1109
|
original_length = scanned_str.bytesize
|
|
1113
1110
|
|
|
1114
|
-
# Handle cases where the number ends with an invalid character.
|
|
1115
|
-
if !scanned_str.empty? && INVALID_NUMBER_TRAILERS.include?(scanned_str[-1])
|
|
1116
|
-
# Do not rewind scanner, simply discard the invalid trailing char (garbage)
|
|
1117
|
-
scanned_str = scanned_str[0...-1]
|
|
1118
1111
|
# Handle cases where what looked like a number is actually a string.
|
|
1119
|
-
# e.g. "123-abc"
|
|
1120
|
-
|
|
1112
|
+
# e.g. "123-abc" or "-Infinity". We exclude strings ending in a comma
|
|
1113
|
+
# to preserve comma recovery logic (e.g. `105,next_key`).
|
|
1114
|
+
if peek_char&.match?(/\p{L}/) && !scanned_str.end_with?(',')
|
|
1121
1115
|
# Roll back the entire scan and re-parse as a string.
|
|
1122
1116
|
@scanner.pos -= original_length
|
|
1123
1117
|
return parse_string
|
|
1124
1118
|
end
|
|
1125
1119
|
|
|
1120
|
+
# Handle cases where the number ends with one or more invalid characters.
|
|
1121
|
+
if !scanned_str.empty? && INVALID_NUMBER_TRAILERS.include?(scanned_str[-1])
|
|
1122
|
+
# Do not rewind scanner, simply discard the invalid trailing chars (garbage)
|
|
1123
|
+
scanned_str = scanned_str[0...-1] while !scanned_str.empty? && INVALID_NUMBER_TRAILERS.include?(scanned_str[-1])
|
|
1124
|
+
end
|
|
1125
|
+
|
|
1126
1126
|
# Reject non-numbers (e.g., stray periods "." or dashes "-" from LLM conversational text)
|
|
1127
1127
|
unless scanned_str.match?(/\d/)
|
|
1128
1128
|
@scanner.pos -= original_length
|
|
@@ -1310,16 +1310,6 @@ module JsonMend
|
|
|
1310
1310
|
obj1.is_a?(Hash) && obj2.is_a?(Hash)
|
|
1311
1311
|
end
|
|
1312
1312
|
|
|
1313
|
-
def strictly_empty?(value)
|
|
1314
|
-
# Check if the value is a container AND if it's empty.
|
|
1315
|
-
case value
|
|
1316
|
-
when String, Array, Hash, Set
|
|
1317
|
-
value.empty?
|
|
1318
|
-
else
|
|
1319
|
-
false
|
|
1320
|
-
end
|
|
1321
|
-
end
|
|
1322
|
-
|
|
1323
1313
|
# Skips whitespaces
|
|
1324
1314
|
def skip_whitespaces
|
|
1325
1315
|
@scanner.skip(/\s+/)
|
data/lib/json_mend/version.rb
CHANGED