json_mend 0.3.2 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 923008e3c63e24de16c3ee6b26097cf4064a32a16bac749c5501e313996238f1
4
- data.tar.gz: c6c6040f9d54fe7604ae7126402886af159aae5e001dca93cbceebf254839a55
3
+ metadata.gz: cf7c2d2fd3815321d7d80912e4ee200cb94a0399220c17219a02f55305f6eccb
4
+ data.tar.gz: 896e1c154c05ce80032072e33d75ddf86335212b0659b9dac93c9c31959da634
5
5
  SHA512:
6
- metadata.gz: c869c17b06f5ed0e46e3f74ccf59c8c374af1431b43ee7d9d59be2170e5ba88e10f83753db36af1e4ebba2cf519273b5f5c32c42fa386978f6a96c22095b063d
7
- data.tar.gz: 770eb1238b3f73261a2130b2a900dfff0bd2770cf0f6b3b38ecee30cafdbfb09e59b87e4df4dd8aba722c5dbbd14bb1b35df509fdc92efbe081d8342ed7e435b
6
+ metadata.gz: 54571b75e4f4448f8c3d87ff2ac2a9d569f5a75e602845ccbc3dda7ff00a935dd8cc2263c18e557e2ffc59ded871467867b0b1fd0371198d05fbaa6f7df46453
7
+ data.tar.gz: 0f0ef4172ffcbeeb0c28220d6af20603c4fdc7917e833dd2bd111343ec257040767d9a9d21d28d416e8a5096cdfda9baf39a63bf7612ff6cf3b7fb332e8036e2
@@ -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
- elsif peek_char&.match?(/\p{L}/)
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+/)
@@ -1330,12 +1320,11 @@ module JsonMend
1330
1320
  # Handle the common 0-offset case
1331
1321
  if offset.zero?
1332
1322
  # peek(1) returns the next BYTE, not character
1333
- byte = @scanner.string.getbyte(@scanner.pos)
1334
- return nil unless byte
1323
+ byte_str = @scanner.peek(1)
1324
+ return nil if byte_str.empty?
1335
1325
 
1336
1326
  # Fast path: If it's a standard ASCII char (0-127), return it directly.
1337
- # Enforcing UTF-8 ensures we don't mix US-ASCII and UTF-8 strings later.
1338
- return byte.chr(Encoding::UTF_8) if byte < 128
1327
+ return byte_str if byte_str.getbyte(0) < 128
1339
1328
 
1340
1329
  # Slow path: If it's a multibyte char (e.g. “), use regex to match the full character.
1341
1330
  return @scanner.check(/./m)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsonMend
4
- VERSION = '0.3.2'
4
+ VERSION = '0.3.4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_mend
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleksii Vasyliev