Skip to content

Conversation

@haxtibal
Copy link
Contributor

@haxtibal haxtibal commented Nov 25, 2025

#2554 added dedent logic, #2555 added hash generation. Tests revealed that hash results for same input were different on Windows and Linux even if CR LF was normalized to LF.

Further investigation revealed that dedent logic didn't work as expected on Windows, because CR LF got split half into the string token, and half into the newline token, which in turn confused the dedent logic. By trial it turned out that "/[^\n\r]+/x" (verbose regex mode, normal string => real newlines) is not the same as "/[^\\n\\r]+/" (normal regex mode, normal string but escaped backslash => symbolized newlines). The former wrongly lets lark scan a \r into NODE_STRING_VALUE.

Thus change to the latter pattern. Note: This fixes only the dedent issue. Hash generation still expects bit-wise identical input and tests would fail if expected hash was sampled on Linux but git converted input \n to \r\n on Windows. We need to re-add code = code.replace(b"\r\n", b"\n") if hash shall be agnostic to line endings.

@haxtibal haxtibal force-pushed the tdmg/fix_lark_newline branch from dadf96a to c3241e8 Compare November 25, 2025 20:24
…DE_STRING_VALUE

strictdoc#2554 added dedent logic, strictdoc-project#2555 added hash generation. that
hash results for same input were different on Windows and Linux even if
CR LF was normalized to LF.

Further investigation revealed that dedent logic didn't work as expected
on Windows, because CR LF got split half into the string token, and half
into the newline token, which in turn confused the dedent logic. By
trial it turned out that "/[^\n\r]+/x" (verbose regex mode, real
newlines) is not the same as "/[^\\n\\r]+/" (normal regex mode,
symbolized newlines). The former wrongly lets lark scan a \r into
NODE_STRING_VALUE.

Thus change to the latter pattern.
@haxtibal haxtibal force-pushed the tdmg/fix_lark_newline branch from c3241e8 to 066f5e2 Compare November 25, 2025 20:24
@stanislaw stanislaw added this to the 2025-Q4 milestone Nov 25, 2025
Copy link
Collaborator

@stanislaw stanislaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thus change to the latter pattern. Note: This fixes only the dedent issue. Hash generation still expects bit-wise identical input and tests would fail if expected hash was sampled on Linux but git converted input \n to \r\n on Windows. We need to re-add code = code.replace(b"\r\n", b"\n") if hash shall be agnostic to line endings.

We didn't remove the code.replace actually, it is still there. I will try to remove the gitattributes now.

@stanislaw stanislaw merged commit e750d02 into strictdoc-project:main Nov 25, 2025
24 checks passed
stanislaw added a commit that referenced this pull request Nov 25, 2025
This reverts #2565. It should be possible because we found the underlying issue
in the lark grammar which broke the integration test on Windows. See #2575.
stanislaw added a commit that referenced this pull request Nov 26, 2025
This reverts #2565. It should be possible because we found the underlying issue
in the lark grammar which broke the integration test on Windows. See #2575.
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.

2 participants