Skip to content

Commit

Permalink
Allow for dashes in attribute parameter names
Browse files Browse the repository at this point in the history
Example:
<a href="https://www.google.com" my-custom-data="someinterestinginformation">

The current regex pattern would parse the name of the second parameter as "data". The new regex also allows for dashes in the name and would extract the full parameter name "my-custom-data".
  • Loading branch information
wberger committed Jun 14, 2019
1 parent b988f46 commit 184156b
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Sources/SwiftRichString/Style/StyleGroup.swift
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public class StyleGroup: StyleProtocol {
private func extractParametersFromTags(_ string: String) -> [String: String]? {
guard let _ = string.firstIndex(of: " ") else { return nil } // no tags

let pattern = "\\w*\\s*=\\s*\"?\\s*([^\"][^\"]*)\\s*\"?.*?" // maybe shorter?
let pattern = "[\\w-]*\\s*=\\s*\"?\\s*([^\"][^\"]*)\\s*\"?.*?" // maybe shorter?
guard let regex = try? NSRegularExpression(pattern: pattern, options: .dotMatchesLineSeparators) else {
return nil
}
Expand Down

0 comments on commit 184156b

Please sign in to comment.