Skip to content

fix: handle edge cases in peek() and construct_scalar() error handling#923

Open
nightcityblade wants to merge 1 commit intoyaml:mainfrom
nightcityblade:fix/issue-906-907
Open

fix: handle edge cases in peek() and construct_scalar() error handling#923
nightcityblade wants to merge 1 commit intoyaml:mainfrom
nightcityblade:fix/issue-906-907

Conversation

@nightcityblade
Copy link
Copy Markdown

Fixes #906, fixes #907

Changes

Fix IndexError in Reader.peek() (#906)

When the input stream is empty or exhausted, peek(index) could raise an IndexError if the requested index exceeds the buffer length even after calling update(). This fix returns '\0' (the end-of-stream sentinel) instead of propagating the IndexError.

Fix AttributeError in construct_scalar() error path (#907)

When construct_scalar() receives an object that is not a Node instance, the error-handling code accessed node.id and node.start_mark unconditionally, causing an AttributeError. This fix uses getattr() with safe fallbacks.

Tests

All 1283 existing tests pass:

1283 passed, 1 warning in 2.29s

- Return '\0' (end-of-stream) from Reader.peek() when the buffer has
  insufficient data after update, instead of raising IndexError.
  Fixes yaml#906.

- Use getattr() for node.id and node.start_mark in construct_scalar()
  error path to avoid AttributeError when node is not a Node instance.
  Fixes yaml#907.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ConstructorError handler accesses node.id causing AttributeError IndexError in scan_tag() and check_key() on empty input

1 participant