mirror of
https://github.com/coteditor/CotEditor.git
synced 2024-09-11 11:25:57 +03:00
Workaround word boundary issue on Swift.Regex
This commit is contained in:
parent
077d5e26e4
commit
d81e694413
@ -9,6 +9,11 @@
|
||||
- [non-AppStore ver.] Update Sparkle from 2.5.1 to 2.5.2.
|
||||
|
||||
|
||||
### Fixes
|
||||
|
||||
- Fix an issue that the application could not open a document containing a specific pattern of letters.
|
||||
|
||||
|
||||
|
||||
4.7.1 (623)
|
||||
--------------------------
|
||||
|
@ -176,7 +176,7 @@ extension String {
|
||||
|
||||
guard !self.isEmpty else { return nil }
|
||||
|
||||
let regex = /\b(charset=|encoding=|@charset|encoding:|coding:) *["']? *(?<encoding>[-_a-zA-Z0-9]+)/
|
||||
let regex = /\b(charset=|encoding=|@charset|encoding:|coding:) *["']? *(?<encoding>[-_a-zA-Z0-9]+)/.wordBoundaryKind(.simple)
|
||||
|
||||
guard let ianaCharSetName = try? regex.firstMatch(in: self.prefix(maxLength))?.encoding else { return nil }
|
||||
|
||||
|
@ -154,6 +154,10 @@ final class EncodingDetectionTests: XCTestCase {
|
||||
|
||||
XCTAssertEqual("<meta charset=\"utf-8\"/>".scanEncodingDeclaration(upTo: 128, suggestedCFEncodings: [utf8, shiftJISX0213, shiftJIS]),
|
||||
.utf8)
|
||||
|
||||
// Swift.Regex with non-simple word boundaries never returns when the given string contains a specific pattern of letters (2023-12 on Swift 5.9).
|
||||
XCTAssertNil("タマゴ,1,".scanEncodingDeclaration(upTo: 128, suggestedCFEncodings: []))
|
||||
XCTAssertNil(try /\ba/.wordBoundaryKind(.simple).firstMatch(in: "タマゴ,1,"))
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user