diff --git a/Example/Package.resolved b/Example/Package.resolved index e7b9ecc..8bd756a 100644 --- a/Example/Package.resolved +++ b/Example/Package.resolved @@ -2,7 +2,7 @@ "object": { "pins": [ { - "package": "cmark-gfm", + "package": "cmark", "repositoryURL": "https://github.com/brokenhandsio/cmark-gfm.git", "state": { "branch": null, @@ -65,7 +65,7 @@ } }, { - "package": "Swim", + "package": "HTML", "repositoryURL": "https://github.com/robb/Swim", "state": { "branch": null, diff --git a/Sources/Saga/String+Slugify.swift b/Sources/Saga/String+Slugify.swift index 9964e30..0c20bb1 100644 --- a/Sources/Saga/String+Slugify.swift +++ b/Sources/Saga/String+Slugify.swift @@ -1,11 +1,13 @@ import Foundation +private let allowedCharacters = CharacterSet(charactersIn: "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_") + public extension CustomStringConvertible { var slugified: String { return self.description - .components(separatedBy: CharacterSet.alphanumerics.union(.whitespaces).inverted) - .joined(separator: "") - .replacingOccurrences(of: " ", with: "-") + .components(separatedBy: allowedCharacters.inverted) + .filter { $0 != "" } + .joined(separator: "-") .lowercased() } } diff --git a/Tests/SagaTests/SagaTests.swift b/Tests/SagaTests/SagaTests.swift index 52d1447..508a3f1 100644 --- a/Tests/SagaTests/SagaTests.swift +++ b/Tests/SagaTests/SagaTests.swift @@ -263,6 +263,9 @@ final class SagaTests: XCTestCase { XCTAssertEqual("one two".slugified, "one-two") XCTAssertEqual("One Two".slugified, "one-two") XCTAssertEqual("One! .Two@".slugified, "one-two") + XCTAssertEqual("one-two".slugified, "one-two") + XCTAssertEqual("one_two".slugified, "one_two") + XCTAssertEqual("ONE-TWO".slugified, "one-two") } static var allTests = [