Skip to content

Commit

Permalink
兼容逻辑中的NaN或长度越界等异常问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Mccc committed Aug 27, 2024
1 parent 14077e1 commit 06a3c41
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 141 deletions.
4 changes: 2 additions & 2 deletions Example/Podfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ PODS:
- FBSnapshotTestCase/SwiftSupport (2.1.4):
- FBSnapshotTestCase/Core
- HandyJSON (5.0.0-beta.1)
- SmartCodable (4.1.6)
- SmartCodable (4.1.7)
- SnapKit (5.6.0)

DEPENDENCIES:
Expand Down Expand Up @@ -39,7 +39,7 @@ SPEC CHECKSUMS:
CleanJSON: 910a36465ce4829e264a902ccf6d1455fdd9f980
FBSnapshotTestCase: 094f9f314decbabe373b87cc339bea235a63e07a
HandyJSON: 582477127ab3ab65bd2e471815f1a7b846856978
SmartCodable: 3dfe748436ce6ccf6a8f04e48171d8d7a3d7b879
SmartCodable: d7272960c97bda49603b864be8453284de095f71
SnapKit: e01d52ebb8ddbc333eefe2132acf85c8227d9c25

PODFILE CHECKSUM: 7f3af03f81934df0c035518074a7abbec8fa9d3f
Expand Down
4 changes: 2 additions & 2 deletions Example/Pods/Local Podspecs/SmartCodable.podspec.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions Example/Pods/Manifest.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

247 changes: 130 additions & 117 deletions Example/Pods/Pods.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 18 additions & 12 deletions Example/SmartCodable/Test2ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,28 @@ class Test2ViewController: BaseViewController {


let dict: [String: Any] = [
"nick_name": "Mccc"
"error": "200",
"code": 400,
"data": [
"code": "abc",
"lyricType": "9999999",
"expriryTime": "NaN"
]
]

let option = SmartDecodingOption.key(.fromSnakeCase)
guard let model = Model.deserialize(from: dict, options: [option]) else { return }

smartPrint(value: model)

let string = model.toJSONString(useMappedKeys: false)
print(string)
guard let model = Model.deserialize(from: dict) else { return }
print(model)
}


struct Model: SmartCodable {
var nickName: String = ""


var error: Int?
var code: Int?
var data: SubModel?
}

struct SubModel: SmartCodable {
var code: Int?
var lyricType: Int?
var expriryTime: Int?
}
}
2 changes: 1 addition & 1 deletion SmartCodable.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

Pod::Spec.new do |s|
s.name = 'SmartCodable'
s.version = '4.1.6'
s.version = '4.1.7'
s.summary = '数据解析库'

s.homepage = 'https://github.com/intsig171'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,14 +172,14 @@ private func _fixedWidthInteger<T: FixedWidthInteger>(from value: JSONValue) ->
case .string(let string):
if let integer = T(string) {
return integer
} else if let float = Double(string) {
return T(float)
} else if let float = Double(string), float.isFinite, float >= Double(T.min) && float <= Double(T.max), let integer = T(exactly: float) {
return integer
}
case .number(let number):
if let integer = T(number) {
return integer
} else if let float = Double(number) {
return T(float)
} else if let float = Double(number), float.isFinite, float >= Double(T.min) && float <= Double(T.max), let integer = T(exactly: float) {
return integer
}
default:
break
Expand Down

0 comments on commit 06a3c41

Please sign in to comment.