Skip to content

Commit 06a3c41

Browse files
author
Mccc
committed
兼容逻辑中的NaN或长度越界等异常问题
1 parent 14077e1 commit 06a3c41

File tree

8 files changed

+160
-141
lines changed

8 files changed

+160
-141
lines changed

Example/Podfile.lock

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ PODS:
88
- FBSnapshotTestCase/SwiftSupport (2.1.4):
99
- FBSnapshotTestCase/Core
1010
- HandyJSON (5.0.0-beta.1)
11-
- SmartCodable (4.1.6)
11+
- SmartCodable (4.1.7)
1212
- SnapKit (5.6.0)
1313

1414
DEPENDENCIES:
@@ -39,7 +39,7 @@ SPEC CHECKSUMS:
3939
CleanJSON: 910a36465ce4829e264a902ccf6d1455fdd9f980
4040
FBSnapshotTestCase: 094f9f314decbabe373b87cc339bea235a63e07a
4141
HandyJSON: 582477127ab3ab65bd2e471815f1a7b846856978
42-
SmartCodable: 3dfe748436ce6ccf6a8f04e48171d8d7a3d7b879
42+
SmartCodable: d7272960c97bda49603b864be8453284de095f71
4343
SnapKit: e01d52ebb8ddbc333eefe2132acf85c8227d9c25
4444

4545
PODFILE CHECKSUM: 7f3af03f81934df0c035518074a7abbec8fa9d3f

Example/Pods/Local Podspecs/SmartCodable.podspec.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Manifest.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Pods.xcodeproj/project.pbxproj

Lines changed: 130 additions & 117 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/Pods/Target Support Files/SmartCodable/SmartCodable-Info.plist

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Example/SmartCodable/Test2ViewController.swift

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,28 @@ class Test2ViewController: BaseViewController {
1616

1717

1818
let dict: [String: Any] = [
19-
"nick_name": "Mccc"
19+
"error": "200",
20+
"code": 400,
21+
"data": [
22+
"code": "abc",
23+
"lyricType": "9999999",
24+
"expriryTime": "NaN"
25+
]
2026
]
2127

22-
let option = SmartDecodingOption.key(.fromSnakeCase)
23-
guard let model = Model.deserialize(from: dict, options: [option]) else { return }
24-
25-
smartPrint(value: model)
26-
27-
let string = model.toJSONString(useMappedKeys: false)
28-
print(string)
28+
guard let model = Model.deserialize(from: dict) else { return }
29+
print(model)
2930
}
3031

31-
3232
struct Model: SmartCodable {
33-
var nickName: String = ""
34-
35-
33+
var error: Int?
34+
var code: Int?
35+
var data: SubModel?
36+
}
37+
38+
struct SubModel: SmartCodable {
39+
var code: Int?
40+
var lyricType: Int?
41+
var expriryTime: Int?
3642
}
3743
}

SmartCodable.podspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
Pod::Spec.new do |s|
1414
s.name = 'SmartCodable'
15-
s.version = '4.1.6'
15+
s.version = '4.1.7'
1616
s.summary = '数据解析库'
1717

1818
s.homepage = 'https://github.com/intsig171'

SmartCodable/Classes/JSONDecoder/Patcher/Patcher+Transformer.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -172,14 +172,14 @@ private func _fixedWidthInteger<T: FixedWidthInteger>(from value: JSONValue) ->
172172
case .string(let string):
173173
if let integer = T(string) {
174174
return integer
175-
} else if let float = Double(string) {
176-
return T(float)
175+
} else if let float = Double(string), float.isFinite, float >= Double(T.min) && float <= Double(T.max), let integer = T(exactly: float) {
176+
return integer
177177
}
178178
case .number(let number):
179179
if let integer = T(number) {
180180
return integer
181-
} else if let float = Double(number) {
182-
return T(float)
181+
} else if let float = Double(number), float.isFinite, float >= Double(T.min) && float <= Double(T.max), let integer = T(exactly: float) {
182+
return integer
183183
}
184184
default:
185185
break

0 commit comments

Comments
 (0)