Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Take into account encoding of source file for syntax error #124188

Closed
Labels
3.12only security fixes3.13bugs and security fixes3.14bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)topic-C-API
@serhiy-storchaka

Description

@serhiy-storchaka

Currently most syntax errors raised in the compiler (except these raised in the parser) usePyErr_ProgramTextObject() to get the line of the code. It does not know the encoding of the source file and interpret it as UTF-8 (failing if it contain non-UTF-8 sequences). The parser uses_PyErr_ProgramDecodedTextObject().

There are two ways to solve this issue:

  • Pass the source file encoding from the parser to the code generator. This may require changing some data structures. But this is more efficient.
  • Detect the encoding inPyErr_ProgramTextObject(). Since the latter is in the public C API, this can also affect the third-party code.

There are other issues withPyErr_ProgramTextObject():

  • It leave the BOM in the first line if the source line contains it. This is not consistent with offsets.
  • For very long lines, it returns the tail of the line that exceeds 1000 bytes. It can be short, it can start with invalid character, it is not consistent with offsets. If return incomplete line, it is better to return the head.

This all applies toPyErr_ProgramText() as well.

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    3.12only security fixes3.13bugs and security fixes3.14bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)topic-C-API

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp