Skip to content

Commit bb6d685

Browse files
fix: relax needsQuote (remove comma from base, tighten NUMERIC_LIKE_RE), delete dead v2 parse_attachment
1 parent 57a7930 commit bb6d685

2 files changed

Lines changed: 2 additions & 37 deletions

File tree

src/gcf/decode_generic.py

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -528,41 +528,6 @@ def _parse_tabular_body(
528528
return rows, i - start
529529

530530

531-
def _parse_attachment(
532-
lines: list[str], line_idx: int, rest: str, depth: int
533-
) -> tuple[str, Any, int]:
534-
if rest and rest[0] == '"':
535-
close_idx = -1
536-
j = 1
537-
while j < len(rest):
538-
if rest[j] == "\\":
539-
j += 2
540-
continue
541-
if rest[j] == '"':
542-
close_idx = j
543-
break
544-
j += 1
545-
if close_idx < 0:
546-
raise ValueError("unterminated_quote")
547-
name = parse_quoted_string(rest[:close_idx + 1])
548-
after_name = rest[close_idx + 1:].lstrip()
549-
else:
550-
sp = rest.find(" ")
551-
if sp < 0:
552-
raise ValueError(f"invalid attachment: {rest}")
553-
name = rest[:sp]
554-
after_name = rest[sp:].lstrip()
555-
556-
if after_name.startswith("{}"):
557-
nested: dict[str, Any] = {}
558-
consumed = _parse_object_body(lines, line_idx + 1, depth, nested)
559-
return name, nested, consumed + 1
560-
if after_name.startswith("["):
561-
arr, consumed = _parse_array_from_header(lines, line_idx, depth, after_name)
562-
return name, arr, consumed
563-
raise ValueError(f"invalid attachment form: {after_name}")
564-
565-
566531
def _parse_expanded_body(
567532
lines: list[str], start: int, depth: int
568533
) -> tuple[list[Any], int]:

src/gcf/scalar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from typing import Any
88

99
_JSON_NUMBER_RE = re.compile(r"^-?(?:0|[1-9]\d*)(?:\.\d+)?(?:[eE][+-]?\d+)?$")
10-
_NUMERIC_LIKE_RE = re.compile(r"^[+-]?\.?\d")
10+
_NUMERIC_LIKE_RE = re.compile(r"^[+-]\.?\d|^\.\d|^0\d")
1111
_BARE_KEY_RE = re.compile(r"^[a-zA-Z_][a-zA-Z0-9_]*$")
1212

1313

@@ -38,7 +38,7 @@ def needs_quote(s: str) -> bool:
3838
return True
3939
for c in s:
4040
o = ord(c)
41-
if c in ('"', "\\", "|", ",") or o < 0x20 or c in ("\n", "\r"):
41+
if c in ('"', "\\", "|") or o < 0x20 or c in ("\n", "\r"):
4242
return True
4343
# C1 control characters
4444
if 0x80 <= o <= 0x9F:

0 commit comments

Comments
 (0)