Merge pull request #234 from stencilproject/check-kvo
Check for property via selector before using value(forKey:)
This commit is contained in:
@@ -4,7 +4,9 @@
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
_None_
|
||||
- Now accessing undefined keys in NSObject does not cause runtime crash and instead renders empty string.
|
||||
[Ilya Puchka](https://github.com/ilyapuchka)
|
||||
[#234](https://github.com/stencilproject/Stencil/pull/234)
|
||||
|
||||
### Breaking Changes
|
||||
|
||||
|
||||
@@ -104,7 +104,9 @@ public struct Variable : Equatable, Resolvable {
|
||||
#if os(Linux)
|
||||
return nil
|
||||
#else
|
||||
current = object.value(forKey: bit)
|
||||
if object.responds(to: Selector(bit)) {
|
||||
current = object.value(forKey: bit)
|
||||
}
|
||||
#endif
|
||||
} else if let value = current {
|
||||
current = Mirror(reflecting: value).getValue(for: bit)
|
||||
|
||||
@@ -148,6 +148,12 @@ func testVariable() {
|
||||
let result = try variable.resolve(context) as? String
|
||||
try expect(result) == "Foo"
|
||||
}
|
||||
|
||||
$0.it("does not crash on KVO") {
|
||||
let variable = Variable("object.fullname")
|
||||
let result = try variable.resolve(context) as? String
|
||||
try expect(result).to.beNil()
|
||||
}
|
||||
#endif
|
||||
|
||||
$0.it("can resolve a value via reflection") {
|
||||
|
||||
Reference in New Issue
Block a user