Fix Sdlc/Dry/RepeatedPathLiteral crash on a string literal with invalid UTF-8 #1213

Open
opened 2026-10-20 14:05:47 +00:00 by jared · 0 comments
Owner

Problem

The cop Sdlc/Dry/RepeatedPathLiteral raises ArgumentError when it inspects a string literal that holds an invalid UTF-8 byte sequence. PathValue#path? calls String#match? on the joined text. match? raises on an invalid string. The missing guard is in path_value.rb lines 30-32. RuboCop reports a cop error for the file, and bin/lint-sweep shows one cop crash on every run. The file plugins/os-sdlc/tests/crc/sweep_bin_test.rb holds the literal "caf\xE9 Old::A\n" at line 258.

Observed

cd plugins/os-sdlc && bundle exec rubocop -d -c .rubocop-sweep.yml --only Sdlc/Dry/RepeatedPathLiteral tests/crc/sweep_bin_test.rb
An error occurred while Sdlc/Dry/RepeatedPathLiteral cop was inspecting /home/jared/dev/cc-os/.claude/worktrees/crc-os-sdlc-run-3/plugins/os-sdlc/tests/crc/sweep_bin_test.rb.
.../lib/os_sdlc/cops/repeated_path_literal/path_value.rb:31:in 'String#match?': invalid byte sequence in UTF-8 (ArgumentError)
              joined.match?(PATH) && joined.match?(NON_SEPARATOR) &&

The call chain is PathValue#path? (line 31), PathValue#value (line 25), RepeatedPathLiteral#valued_places (repeated_path_literal.rb:31). The #1210 implementer reported: "The one RepeatedPathLiteral cop error is still there."

Reproduce

cd plugins/os-sdlc && bundle exec rubocop -d -c .rubocop-sweep.yml --only Sdlc/Dry/RepeatedPathLiteral tests/crc/sweep_bin_test.rb

Approach

PathValue#path? returns false for a string that is not valid_encoding?. An invalid string is not a path literal.

Required work:

  1. In PathValue#path?, return false when joined.valid_encoding? is false — check: present valid_encoding? in plugins/os-sdlc/lib/os_sdlc/cops/repeated_path_literal/path_value.rb
  2. Add a cop test with a source line that holds an invalid byte, for example "caf\xE9". The test expects no offense and no raise.

Acceptance criteria

  1. Given a source file with the literal "caf\xE9 Old::A\n", when the cop inspects it, then it raises no error and reports no offense for that literal.
  2. Given bin/lint-sweep run from plugins/os-sdlc, when it finishes, then it reports no cop error for tests/crc/sweep_bin_test.rb.
  3. Given a valid repeated path literal, when the cop inspects it, then it still reports the offense.

Owner sketch

class RuboCop::Cop::Sdlc::Dry::RepeatedPathLiteral::PathValue
  def value
end

Origin

  • Trigger: bin/lint-sweep in CRC run 3 (HANDOFF gate baseline: "1 unrelated cop crash")
  • Improvised this session: none; the implementers listed the crash as a known baseline error
  • Chain: cop crash on one file ← String#match? on an invalid UTF-8 literal ("caf\xE9 Old::A\n", tests/crc/sweep_bin_test.rb:258) ← DESIGN (plugins/os-sdlc/lib/os_sdlc/cops/repeated_path_literal/path_value.rb:31 does not guard encoding)
  • Root candidate: none found
  • Where: plugins/os-sdlc/lib/os_sdlc/cops/repeated_path_literal/path_value.rb
  • Session: 2e167079-f404-4139-9cfa-6c0c937ce9f0
  • Transcript: /home/jared/.claude/projects/-home-jared-dev-cc-os--claude-worktrees-crc-os-sdlc-run-3/2e167079-f404-4139-9cfa-6c0c937ce9f0.jsonl

VERDICT: CREATE

## Problem The cop `Sdlc/Dry/RepeatedPathLiteral` raises `ArgumentError` when it inspects a string literal that holds an invalid UTF-8 byte sequence. `PathValue#path?` calls `String#match?` on the joined text. `match?` raises on an invalid string. The missing guard is in `path_value.rb` lines 30-32. RuboCop reports a cop error for the file, and `bin/lint-sweep` shows one cop crash on every run. The file `plugins/os-sdlc/tests/crc/sweep_bin_test.rb` holds the literal `"caf\xE9 Old::A\n"` at line 258. ## Observed ``` cd plugins/os-sdlc && bundle exec rubocop -d -c .rubocop-sweep.yml --only Sdlc/Dry/RepeatedPathLiteral tests/crc/sweep_bin_test.rb ``` ``` An error occurred while Sdlc/Dry/RepeatedPathLiteral cop was inspecting /home/jared/dev/cc-os/.claude/worktrees/crc-os-sdlc-run-3/plugins/os-sdlc/tests/crc/sweep_bin_test.rb. .../lib/os_sdlc/cops/repeated_path_literal/path_value.rb:31:in 'String#match?': invalid byte sequence in UTF-8 (ArgumentError) joined.match?(PATH) && joined.match?(NON_SEPARATOR) && ``` The call chain is `PathValue#path?` (line 31), `PathValue#value` (line 25), `RepeatedPathLiteral#valued_places` (`repeated_path_literal.rb:31`). The #1210 implementer reported: "The one `RepeatedPathLiteral` cop error is still there." ## Reproduce ``` cd plugins/os-sdlc && bundle exec rubocop -d -c .rubocop-sweep.yml --only Sdlc/Dry/RepeatedPathLiteral tests/crc/sweep_bin_test.rb ``` ## Approach `PathValue#path?` returns false for a string that is not `valid_encoding?`. An invalid string is not a path literal. Required work: 1. In `PathValue#path?`, return false when `joined.valid_encoding?` is false — check: present `valid_encoding?` in `plugins/os-sdlc/lib/os_sdlc/cops/repeated_path_literal/path_value.rb` 2. Add a cop test with a source line that holds an invalid byte, for example `"caf\xE9"`. The test expects no offense and no raise. ## Acceptance criteria 1. Given a source file with the literal `"caf\xE9 Old::A\n"`, when the cop inspects it, then it raises no error and reports no offense for that literal. 2. Given `bin/lint-sweep` run from `plugins/os-sdlc`, when it finishes, then it reports no cop error for `tests/crc/sweep_bin_test.rb`. 3. Given a valid repeated path literal, when the cop inspects it, then it still reports the offense. ## Owner sketch ```ruby class RuboCop::Cop::Sdlc::Dry::RepeatedPathLiteral::PathValue def value end ``` ## Origin - Trigger: bin/lint-sweep in CRC run 3 (HANDOFF gate baseline: "1 unrelated cop crash") - Improvised this session: none; the implementers listed the crash as a known baseline error - Chain: cop crash on one file ← `String#match?` on an invalid UTF-8 literal (`"caf\xE9 Old::A\n"`, tests/crc/sweep_bin_test.rb:258) ← DESIGN (plugins/os-sdlc/lib/os_sdlc/cops/repeated_path_literal/path_value.rb:31 does not guard encoding) - Root candidate: none found - Where: plugins/os-sdlc/lib/os_sdlc/cops/repeated_path_literal/path_value.rb - Session: 2e167079-f404-4139-9cfa-6c0c937ce9f0 - Transcript: /home/jared/.claude/projects/-home-jared-dev-cc-os--claude-worktrees-crc-os-sdlc-run-3/2e167079-f404-4139-9cfa-6c0c937ce9f0.jsonl VERDICT: CREATE
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
jared/cc-os#1213
No description provided.