Skip to content

Conversation

@LoukasPap
Copy link

@LoukasPap LoukasPap commented Jan 12, 2026

Fixes issue 234

  • Increase to 2 supported addresses for line number command (=)
  • Add 2 integration tests

UPDATE
The PR now solves the problem where invalid POSIX commands with address range were being allowed when they shouldn't. These commands are: a, i, =, l, q, r (maybe there are some more I missed).

@github-actions
Copy link

GNU sed testsuite comparison:

Test results comparison:
  Current:   TOTAL: 64 / PASSED: 8 / FAILED: 56 / SKIPPED: 0
  Reference: TOTAL: 64 / PASSED: 8 / FAILED: 56 / SKIPPED: 0

@codecov
Copy link

codecov bot commented Jan 12, 2026

Codecov Report

❌ Patch coverage is 64.70588% with 6 lines in your changes missing coverage. Please review.
✅ Project coverage is 82.04%. Comparing base (db58849) to head (dd23a6f).
⚠️ Report is 18 commits behind head on main.

Files with missing lines Patch % Lines
src/sed/compiler.rs 57.14% 5 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #260      +/-   ##
==========================================
- Coverage   82.15%   82.04%   -0.11%     
==========================================
  Files          13       13              
  Lines        5324     5337      +13     
  Branches      293      295       +2     
==========================================
+ Hits         4374     4379       +5     
- Misses        948      955       +7     
- Partials        2        3       +1     
Flag Coverage Δ
macos_latest 82.48% <64.70%> (-0.12%) ⬇️
ubuntu_latest 82.60% <64.70%> (-0.11%) ⬇️
windows_latest 0.00% <0.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link

GNU sed testsuite comparison:

Test results comparison:
  Current:   TOTAL: 64 / PASSED: 8 / FAILED: 56 / SKIPPED: 0
  Reference: TOTAL: 64 / PASSED: 8 / FAILED: 56 / SKIPPED: 0

@dspinellis
Copy link
Collaborator

Thank you! This is a GNU extension, so the feature should not be available under --posix. Please also squash all commits into one.

@LoukasPap
Copy link
Author

Got it! I'll fix these and push again.

@LoukasPap
Copy link
Author

LoukasPap commented Jan 20, 2026

Found out that the problem happens with the l (list) command too (we allow address range with --posix enabled but it should not be allowed). Should I fix it here or open a different issue for this?

@dspinellis
Copy link
Collaborator

I'd suggest one commit for all commands. Try to unify the check for POSIX.

@github-actions
Copy link

GNU sed testsuite comparison:

Test results comparison:
  Current:   TOTAL: 64 / PASSED: 15 / FAILED: 49 / SKIPPED: 0
  Reference: TOTAL: 64 / PASSED: 15 / FAILED: 49 / SKIPPED: 0

2 similar comments
@github-actions
Copy link

GNU sed testsuite comparison:

Test results comparison:
  Current:   TOTAL: 64 / PASSED: 15 / FAILED: 49 / SKIPPED: 0
  Reference: TOTAL: 64 / PASSED: 15 / FAILED: 49 / SKIPPED: 0

@github-actions
Copy link

GNU sed testsuite comparison:

Test results comparison:
  Current:   TOTAL: 64 / PASSED: 15 / FAILED: 49 / SKIPPED: 0
  Reference: TOTAL: 64 / PASSED: 15 / FAILED: 49 / SKIPPED: 0

@LoukasPap LoukasPap force-pushed the main branch 2 times, most recently from 81e0901 to 698f2b7 Compare January 21, 2026 17:07
@LoukasPap
Copy link
Author

LoukasPap commented Jan 21, 2026

Squashed all my commits having removed the merge commit which was not mine.

The POSIX check now happens in one place. I will update the README.md too.

);
}

if context.is_posix_enabled() && is_gnu_extension(ch, n_addr) {
Copy link
Author

@LoukasPap LoukasPap Jan 21, 2026

Choose a reason for hiding this comment

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

Now that I see it, maybe it would be more readable if we extracted this in a function named e.g. is_invalid_posix_cmd(...) or violates_posix(...).

Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider storing in cmd_spec n_addr_posix in addition to n_addr.

@github-actions
Copy link

GNU sed testsuite comparison:

Test results comparison:
  Current:   TOTAL: 64 / PASSED: 15 / FAILED: 49 / SKIPPED: 0
  Reference: TOTAL: 64 / PASSED: 15 / FAILED: 49 / SKIPPED: 0

…flag usage with GNU only extensions

- Add a context parameter in get_verified_cmd_spec function and update the relative test cases
- Add integration tests for address range
@github-actions
Copy link

GNU sed testsuite comparison:

Test results comparison:
  Current:   TOTAL: 64 / PASSED: 15 / FAILED: 49 / SKIPPED: 0
  Reference: TOTAL: 64 / PASSED: 15 / FAILED: 49 / SKIPPED: 0

@dspinellis
Copy link
Collaborator

I see you're progressing! Try running the various CI tasks locally to avoid CI failures. Please also close the PRs that you've folded into this one.

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 22, 2026

CodSpeed Performance Report

Merging this PR will degrade performance by 3.62%

Comparing LoukasPap:main (a73f56d) with main (398ee76)

Summary

⚡ 1 improved benchmark
❌ 1 regressed benchmark
✅ 9 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
access_log_subst 1.2 s 1.1 s +6.17%
access_log_translit 784.3 ms 813.7 ms -3.62%

@LoukasPap
Copy link
Author

These two tests are failing because the supported addresses are now 2 and not 1 (like the tests assert):

  1. test_lookup_text_command

    sed/src/sed/compiler.rs

    Lines 1309 to 1314 in 398ee76

    #[test]
    fn test_lookup_text_command() {
    let (lines, line) = make_providers("123abc");
    let cmd = get_cmd_spec(&lines, &line, 'a').unwrap();
    assert_eq!(cmd.n_addr, 1);
    }
  2. test_valid_command_spec

    sed/src/sed/compiler.rs

    Lines 1416 to 1425 in 398ee76

    #[test]
    fn test_valid_command_spec() {
    let lines = ScriptLineProvider::with_active_state("input.sed", 4);
    let line = char_provider_from("a"); // valid command
    let result = get_verified_cmd_spec(&lines, &line, 1);
    assert!(result.is_ok());
    let spec = result.unwrap();
    assert_eq!(spec.n_addr, 1);
    }

Would it be "correct" to change the tests to check for 2 addresses; What I mean is, do these tests represent the standard sed behavior (1 address) and not the 'GNU-extended' behavior (with 2 addresses) and thus changing them would be wrong?

I hope I am clear :)


impl ProcessingContext {
/// Check if POSIX extension is enabled
pub fn is_posix_enabled(&self) -> bool {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Such trivial accessors are avoided in Rust code.

@dspinellis
Copy link
Collaborator

I would expect that rather than storing / returning a number you would store

These two tests are failing because the supported addresses are now 2 and not 1 (like the tests assert):

1. `test_lookup_text_command`
   https://github.com/uutils/sed/blob/398ee76b79ba52768c1df214d516b2ad5c173882/src/sed/compiler.rs#L1309-L1314

2. `test_valid_command_spec`
   https://github.com/uutils/sed/blob/398ee76b79ba52768c1df214d516b2ad5c173882/src/sed/compiler.rs#L1416-L1425

Would it be "correct" to change the tests to check for 2 addresses; What I mean is, do these tests represent the standard sed behavior (1 address) and not the 'GNU-extended' behavior (with 2 addresses) and thus changing them would be wrong?

I hope I am clear :)

I suggest that you also store and process n_addr_posix and add corresponding tests.

Copy link
Collaborator

@dspinellis dspinellis left a comment

Choose a reason for hiding this comment

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

Please consider the initial comments I made on the code and fix the CI errors. Will then follow-up with a more complete review.

);
}

if context.is_posix_enabled() && is_gnu_extension(ch, n_addr) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Consider storing in cmd_spec n_addr_posix in addition to n_addr.

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.

Address range validation difference for line number command

2 participants