Skip to content

Conversation

@jgarzik
Copy link
Contributor

@jgarzik jgarzik commented Nov 30, 2025

No description provided.

@jgarzik jgarzik requested a review from Copilot November 30, 2025 06:32
@jgarzik jgarzik self-assigned this Nov 30, 2025
@jgarzik jgarzik added bug Something isn't working enhancement New feature or request cleanup labels Nov 30, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR rewrites the asa utility to fix correctness issues and adds comprehensive test coverage. The rewrite simplifies the implementation by processing lines immediately rather than accumulating them in a state machine, resulting in clearer and more maintainable code.

Key changes:

  • Removed the AsaState struct and associated complexity
  • Implemented direct line-by-line processing with proper POSIX-compliant behavior
  • Added 20 comprehensive test cases covering edge cases, POSIX requirements, and FORTRAN-style output

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
text/tests/text-tests.rs Added asa test module declaration
text/tests/asa/mod.rs New comprehensive test suite with 20 test cases covering empty input, control characters (' ', '0', '1', '+', '-'), edge cases, and FORTRAN-style reports
text/asa.rs Complete rewrite: removed AsaState struct, simplified to direct line processing, fixed POSIX compliance for '+' as first character, removed malformed line error, removed unused gettext import

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +49 to +50
let line = if line_end > 1 {
&raw_line[1..line_end]
Copy link

Copilot AI Nov 30, 2025

Choose a reason for hiding this comment

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

The line extraction logic has two issues with multi-byte UTF-8 characters:

  1. It uses hardcoded byte index 1 and comparison line_end > 1, assuming the first character is always single-byte ASCII
  2. If a multi-byte UTF-8 character is encountered as the control character, raw_line[1..line_end] will panic with a "byte index is not a char boundary" error

While the ASA format typically uses ASCII control characters, the code should handle this gracefully. The fix should:

  • Replace 1 with ch.len_utf8() in the slice
  • Replace line_end > 1 with line_end > ch.len_utf8()

Example: let line = if line_end > ch.len_utf8() { &raw_line[ch.len_utf8()..line_end] } else { "" };

Suggested change
let line = if line_end > 1 {
&raw_line[1..line_end]
let line = if line_end > ch.len_utf8() {
&raw_line[ch.len_utf8()..line_end]

Copilot uses AI. Check for mistakes.
@jgarzik jgarzik merged commit 75f9d99 into main Nov 30, 2025
10 checks passed
@jgarzik jgarzik deleted the updates branch November 30, 2025 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cleanup enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants