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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae2e6bb67d6227598226e35e852e4b4ae7f681e6ce8bcb94d11bd5e61c74a989
4
- data.tar.gz: 0fbd0b9cc00caa626a794e2024d34d0f31d9bf407f31e7ce8cbb0e1b78c9773d
3
+ metadata.gz: cf7c2d2fd3815321d7d80912e4ee200cb94a0399220c17219a02f55305f6eccb
4
+ data.tar.gz: 896e1c154c05ce80032072e33d75ddf86335212b0659b9dac93c9c31959da634
5
5
  SHA512:
6
- metadata.gz: afd9daaec420a7bdb29ed2bf5d6438e5b335d2990eeae24503ab0fc10e6221a299dbcf63f4d0b09e093a7a03a523f5fa90db5ff46fc7cbec40670cac71f4955a
7
- data.tar.gz: 730768fa1d1954c626c88c17b8afc3ec7e4726abcd2b4602072453e35d910da0cd6e1b92c5841e571abcd22c6bc7e02df65de7b8dfab45e9cd1210de24ca6f94
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+/)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module JsonMend
4
- VERSION = '0.3.3'
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.3
4
+ version: 0.3.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleksii Vasyliev