Skip to content

Commit c613134

Browse files
committed
Merge remote-tracking branch 'origin/master' into swift-4.0-branch
2 parents ce26035 + df5e826 commit c613134

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

CoreFoundation/String.subproj/CFRegularExpression.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,8 +133,9 @@ _CFRegularExpressionRef _CFRegularExpressionCreate(CFAllocatorRef allocator, CFS
133133
if (regex == NULL || U_FAILURE(errorCode)) {
134134
// ??? do we need more detailed errors here?
135135
if (errorPtr) {
136-
CFStringRef keys[] = {
137-
CFSTR("NSInvalidValue")
136+
CFStringRef key = CFSTR("NSInvalidValue");
137+
CFTypeRef keys[] = {
138+
key
138139
};
139140
CFTypeRef values[] = {
140141
pattern

Foundation/NSRegularExpression.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ open class NSRegularExpression: NSObject, NSCopying, NSCoding {
8585
if let regex = _CFRegularExpressionCreate(kCFAllocatorSystemDefault, pattern._cfObject, opt, &error) {
8686
_internal = regex
8787
} else {
88-
throw error!.takeRetainedValue()._nsObject
88+
throw error!.takeRetainedValue()
8989
}
9090
}
9191

TestFoundation/TestNSRegularExpression.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class TestNSRegularExpression : XCTestCase {
2929
("test_Equal", test_Equal),
3030
("test_NSCoding", test_NSCoding),
3131
("test_defaultOptions", test_defaultOptions),
32+
("test_badPattern", test_badPattern),
3233
]
3334
}
3435

@@ -372,4 +373,14 @@ class TestNSRegularExpression : XCTestCase {
372373
let str = NSMutableString(string: text)
373374
XCTAssertEqual(regex!.replaceMatches(in: str, range: range, withTemplate: "$1-$2-$3"), 1)
374375
}
376+
377+
func test_badPattern() {
378+
do {
379+
_ = try NSRegularExpression(pattern: "(", options: [])
380+
XCTFail()
381+
} catch {
382+
let err = String(describing: error)
383+
XCTAssertEqual(err, "Error Domain=NSCocoaErrorDomain Code=2048 \"(null)\" UserInfo={NSInvalidValue=(}")
384+
}
385+
}
375386
}

0 commit comments

Comments
 (0)