Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when disable command is preceded by unicode character #5976

Merged
merged 4 commits into from
Mar 15, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Rename actionString to commandString
  • Loading branch information
SimplyDanny committed Mar 15, 2025
commit 471f68e0f3ecfc9f2fbce9cae852b7cb088002aa
10 changes: 5 additions & 5 deletions Source/SwiftLintCore/Models/Command.swift
Original file line number Diff line number Diff line change
@@ -82,11 +82,11 @@ public struct Command: Equatable {

/// Creates a command based on the specified parameters.
///
/// - parameter actionString: The string in the command's definition describing its action.
/// - parameter line: The line in the source file where this command is defined.
/// - parameter range: The range of the command in the line (0-based).
public init(actionString: String, line: Int, range: Range<Int>) {
let scanner = Scanner(string: actionString)
/// - parameter commandString: The whole command string as found in the code.
/// - parameter line: The line in the source file where this command is defined.
/// - parameter range: The range of the command in the line (0-based).
public init(commandString: String, line: Int, range: Range<Int>) {
let scanner = Scanner(string: commandString)
_ = scanner.scanString("swiftlint:")
// (enable|disable)(:previous|:this|:next)
guard let actionAndModifierString = scanner.scanUpToString(" ") else {
2 changes: 1 addition & 1 deletion Source/SwiftLintCore/Visitors/CommandVisitor.swift
Original file line number Diff line number Diff line change
@@ -32,7 +32,7 @@ final class CommandVisitor: SyntaxVisitor {
break
}
let command = Command(
actionString: String(comment[lower...]),
commandString: String(comment[lower...]),
line: location.line,
range: character..<(character + piece.sourceLength.utf8Length - offset)
)
2 changes: 1 addition & 1 deletion Tests/FrameworkTests/CommandTests.swift
Original file line number Diff line number Diff line change
@@ -10,7 +10,7 @@ private extension Command {
let nsString = string.bridge()
guard nsString.length > 7 else { return nil }
let subString = nsString.substring(with: NSRange(location: 3, length: nsString.length - 4))
self.init(actionString: subString, line: 1, range: 4..<nsString.length)
self.init(commandString: subString, line: 1, range: 4..<nsString.length)
}
}