Fix Sdlc/Dry/RepeatedPathLiteral crash on a string literal with invalid UTF-8 #1213
Labels
No labels
P0
P1
P2
P3
bug
category/code-change
category/cross-repo
category/eval-run
category/investigation
category/no-test-target
category/owner-ruling
category/prose-artifact
category/recurring-chore
category/structure
category/umbrella
crc-refactor
create
delete
enhancement
filed-by/agent
filed-by/user
frozen
lint-rule
needs-info
needs-triage
next
plugin/cc-architect
plugin/os
plugin/os-adr
plugin/os-aidd-lint
plugin/os-backlog
plugin/os-context
plugin/os-doc-hygiene
plugin/os-sdlc
plugin/os-vault
project/cc-os
ready-for-agent
ready-for-human
recurring
review
rule-proposal
update
waiting
wayfinder:grilling
wayfinder:map
wayfinder:map
wayfinder:research
wayfinder:task
wayfinder:task
wontfix
worklist/deviations
worklist/lint-rule
worklist/new-implement-build
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
jared/cc-os#1213
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Problem
The cop
Sdlc/Dry/RepeatedPathLiteralraisesArgumentErrorwhen it inspects a string literal that holds an invalid UTF-8 byte sequence.PathValue#path?callsString#match?on the joined text.match?raises on an invalid string. The missing guard is inpath_value.rblines 30-32. RuboCop reports a cop error for the file, andbin/lint-sweepshows one cop crash on every run. The fileplugins/os-sdlc/tests/crc/sweep_bin_test.rbholds the literal"caf\xE9 Old::A\n"at line 258.Observed
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 oneRepeatedPathLiteralcop error is still there."Reproduce
Approach
PathValue#path?returns false for a string that is notvalid_encoding?. An invalid string is not a path literal.Required work:
PathValue#path?, return false whenjoined.valid_encoding?is false — check: presentvalid_encoding?inplugins/os-sdlc/lib/os_sdlc/cops/repeated_path_literal/path_value.rb"caf\xE9". The test expects no offense and no raise.Acceptance criteria
"caf\xE9 Old::A\n", when the cop inspects it, then it raises no error and reports no offense for that literal.bin/lint-sweeprun fromplugins/os-sdlc, when it finishes, then it reports no cop error fortests/crc/sweep_bin_test.rb.Owner sketch
Origin
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)VERDICT: CREATE