Skip to content

Commit f0c0a45

Browse files
committed
Use RFC 4648 for base64 encoding, fix force_try violation
Replace Foundation's base64EncodedString with RFC 4648 compliant implementation. Handle encoding failure gracefully with null fallback.
1 parent 8411605 commit f0c0a45

3 files changed

Lines changed: 14 additions & 41 deletions

File tree

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,7 @@ Thumbs.db
2323
!CODE_OF_CONDUCT.md
2424
!SECURITY.md
2525
!**/*.docc/**/*.md
26+
27+
28+
# SwiftLint Remote Config Cache
29+
.swiftlint/RemoteConfigCache

.swiftlint.yml

Lines changed: 4 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,6 @@
1-
disabled_rules:
2-
- line_length
3-
- trailing_comma
4-
- redundant_discardable_let
5-
- identifier_name # Allow short variable names (i, x, y, etc.)
6-
- large_tuple # Allow tuples with more than 2 members
7-
- optional_data_string_conversion # False positive with String(decoding:as:)
8-
- for_where # False positives when for loops have complex logic, not just filtering
9-
- todo # Allow TODO comments for tracking future work
10-
- type_body_length # Don't enforce maximum type body length
11-
- nesting # Allow nested types for hierarchical APIs
12-
- type_name # Allow flexible test suite naming (lowercase, special chars, etc.)
13-
- cyclomatic_complexity # Allow complex inline logic over helper extraction
14-
- implicit_optional_initialization # Allow explicit = nil initialization
15-
- function_body_length # Allow longer inline functions
16-
- file_length # Allow longer files
1+
# SwiftLint configuration
2+
# Inherits from the shared parent configuration in swift-standards
173

18-
opt_in_rules:
19-
- explicit_init
20-
- closure_spacing
21-
- empty_count
22-
- empty_string
23-
- fatal_error_message
24-
- first_where
25-
- joined_default_parameter
26-
- operator_usage_whitespace
27-
- overridden_super_call
4+
parent_config: https://raw.githubusercontent.com/swift-standards/swift-standards/main/.swiftlint.yml
285

29-
included:
30-
- Sources
31-
- Tests
32-
33-
excluded:
34-
- .build
35-
- Carthage
36-
- Pods
37-
- fastlane
38-
39-
# Function parameter count (kept as a reasonable limit)
40-
function_parameter_count:
41-
warning: 6
42-
error: 8
6+
# Package-specific overrides (if needed)

Sources/HTML/HTML Enhancements/String.StringInterpolation.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import Foundation
99
import HTML_Rendering
10+
import RFC_4648
1011

1112
extension String.StringInterpolation {
1213
public mutating func appendInterpolation(html value: some HTML.View) {
@@ -29,7 +30,11 @@ extension String.StringInterpolation {
2930

3031
extension String.StringInterpolation {
3132
public mutating func appendInterpolation(json value: some Codable) {
32-
let json = try! JSONEncoder().encode(value).base64EncodedString()
33+
guard let data = try? JSONEncoder().encode(value) else {
34+
appendLiteral("`null`")
35+
return
36+
}
37+
let json = Array(data).base64.encoded()
3338
appendLiteral(#"`\#(json)`"#)
3439
}
3540
}

0 commit comments

Comments
 (0)