Skip to content

Commit

Permalink
Fix Entities UTF16 escape
Browse files Browse the repository at this point in the history
  • Loading branch information
Nabil Chatbi committed Jun 28, 2017
1 parent 9898dd9 commit 312cb57
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Sources/Entities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,8 @@ public class Entities {
//let length = UInt32(string.characters.count)

var codePoint: UnicodeScalar
for ch in string.characters {
codePoint = ch.unicodeScalar
for ch in string.unicodeScalars {
codePoint = ch

if (normaliseWhite) {
if (codePoint.isWhitespace) {
Expand Down
6 changes: 6 additions & 0 deletions Sources/StringBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ open class StringBuilder {
return self
}

@discardableResult
open func append(_ value: UnicodeScalar) -> StringBuilder {
stringValue.append(contentsOf: value.description.characters)
return self
}

@discardableResult
open func insert<T: CustomStringConvertible>(_ offset: Int, _ value: T) -> StringBuilder {
stringValue.insert(contentsOf: value.description.characters, at: offset)
Expand Down
2 changes: 1 addition & 1 deletion SwiftSoup.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

Pod::Spec.new do |s|
s.name = 'SwiftSoup'
s.version = '1.4.0'
s.version = '1.4.1'
s.summary = 'Swift HTML Parser / Reader, XML , with best of DOM, CSS, and jquery'

# This description is used to generate tags and improve search results.
Expand Down
17 changes: 16 additions & 1 deletion Tests/SwiftSoupTests/DocumentTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,20 @@ class DocumentTest: XCTestCase {

return doc
}


func testThai()
{
let str = "บังคับ"
guard let doc = try? SwiftSoup.parse(str) else {
XCTFail()
return}
guard let txt = try? doc.html() else {
XCTFail()
return}
XCTAssertEqual("<html>\n <head></head>\n <body>\n บังคับ\n </body>\n</html>", txt)
}

//todo:
// func testShiftJisRoundtrip()throws {
// let input =
Expand Down Expand Up @@ -482,7 +496,8 @@ class DocumentTest: XCTestCase {
("testMetaCharsetUpdateXmlNoCharset", testMetaCharsetUpdateXmlNoCharset),
("testMetaCharsetUpdateXmlDisabled", testMetaCharsetUpdateXmlDisabled),
("testMetaCharsetUpdateXmlDisabledNoChanges", testMetaCharsetUpdateXmlDisabledNoChanges),
("testMetaCharsetUpdatedDisabledPerDefault", testMetaCharsetUpdatedDisabledPerDefault)
("testMetaCharsetUpdatedDisabledPerDefault", testMetaCharsetUpdatedDisabledPerDefault),
("testThai",testThai)
]
}()

Expand Down

0 comments on commit 312cb57

Please sign in to comment.