• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

supabase / supabase-swift / 17238365990

26 Aug 2025 12:38PM UTC coverage: 48.936% (-28.5%) from 77.386%
17238365990

Pull #781

github

web-flow
Merge 95ac7642e into e4d8c3718
Pull Request #781: RFC: Migrate HTTP networking from URLSession to Alamofire

287 of 986 new or added lines in 26 files covered. (29.11%)

1397 existing lines in 30 files now uncovered.

3448 of 7046 relevant lines covered (48.94%)

5.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

72.22
/Sources/Helpers/FoundationExtensions.swift
1
//
2
//  FoundationExtensions.swift
3
//
4
//
5
//  Created by Guilherme Souza on 23/04/24.
6
//
7

8
import Foundation
9

10
#if canImport(FoundationNetworking)
11
  import FoundationNetworking
12

13
  package let NSEC_PER_SEC: UInt64 = 1_000_000_000
14
  package let NSEC_PER_MSEC: UInt64 = 1_000_000
15
#endif
16

17
extension Result {
UNCOV
18
  package var value: Success? {
×
UNCOV
19
    if case let .success(value) = self {
×
UNCOV
20
      value
×
UNCOV
21
    } else {
×
UNCOV
22
      nil
×
UNCOV
23
    }
×
UNCOV
24
  }
×
25

UNCOV
26
  package var error: Failure? {
×
UNCOV
27
    if case let .failure(error) = self {
×
UNCOV
28
      error
×
UNCOV
29
    } else {
×
UNCOV
30
      nil
×
UNCOV
31
    }
×
UNCOV
32
  }
×
33
}
34

35
extension URL {
36
  // package var queryItems: [URLQueryItem] {
37
  //   get {
38
  //     URLComponents(url: self, resolvingAgainstBaseURL: false)?.percentEncodedQueryItems ?? []
39
  //   }
40
  //   set {
41
  //     appendOrUpdateQueryItems(newValue)
42
  //   }
43
  // }
44

45
  package mutating func appendQueryItems(_ queryItems: [URLQueryItem]) {
16✔
46
    guard !queryItems.isEmpty else {
16✔
47
      return
12✔
48
    }
12✔
49

4✔
50
    guard var components = URLComponents(url: self, resolvingAgainstBaseURL: false) else {
4✔
51
      return
×
52
    }
4✔
53

4✔
54
    let currentQueryItems = components.percentEncodedQueryItems ?? []
4✔
55

4✔
56
    components.percentEncodedQueryItems =
4✔
57
      currentQueryItems
4✔
58
      + queryItems.map {
5✔
59
        URLQueryItem(
5✔
60
          name: escape($0.name),
5✔
61
          value: $0.value.map(escape)
5✔
62
        )
5✔
63
      }
5✔
64

4✔
65
    if let newURL = components.url {
4✔
66
      self = newURL
4✔
67
    }
4✔
68
  }
4✔
69

70
  package func appendingQueryItems(_ queryItems: [URLQueryItem]) -> URL {
16✔
71
    var url = self
16✔
72
    url.appendQueryItems(queryItems)
16✔
73
    return url
16✔
74
  }
16✔
75

76
  // package mutating func appendOrUpdateQueryItems(_ queryItems: [URLQueryItem]) {
77
  //   guard !queryItems.isEmpty else {
78
  //     return
79
  //   }
80

81
  //   guard var components = URLComponents(url: self, resolvingAgainstBaseURL: false) else {
82
  //     return
83
  //   }
84

85
  //   var currentQueryItems = components.percentEncodedQueryItems ?? []
86

87
  //   for var queryItem in queryItems {
88
  //     queryItem.name = escape(queryItem.name)
89
  //     queryItem.value = queryItem.value.map(escape)
90
  //     if let index = currentQueryItems.firstIndex(where: { $0.name == queryItem.name }) {
91
  //       currentQueryItems[index] = queryItem
92
  //     } else {
93
  //       currentQueryItems.append(queryItem)
94
  //     }
95
  //   }
96

97
  //   components.percentEncodedQueryItems = currentQueryItems
98

99
  //   if let newURL = components.url {
100
  //     self = newURL
101
  //   }
102
  // }
103

104
  // package func appendingOrUpdatingQueryItems(_ queryItems: [URLQueryItem]) -> URL {
105
  //   var url = self
106
  //   url.appendOrUpdateQueryItems(queryItems)
107
  //   return url
108
  // }
109
}
110

111
func escape(_ string: String) -> String {
10✔
112
  string.addingPercentEncoding(withAllowedCharacters: .sbURLQueryAllowed) ?? string
10✔
113
}
10✔
114

115
extension CharacterSet {
116
  /// Creates a CharacterSet from RFC 3986 allowed characters.
117
  ///
118
  /// RFC 3986 states that the following characters are "reserved" characters.
119
  ///
120
  /// - General Delimiters: ":", "#", "[", "]", "@", "?", "/"
121
  /// - Sub-Delimiters: "!", "$", "&", "'", "(", ")", "*", "+", ",", ";", "="
122
  ///
123
  /// In RFC 3986 - Section 3.4, it states that the "?" and "/" characters should not be escaped to allow
124
  /// query strings to include a URL. Therefore, all "reserved" characters with the exception of "?" and "/"
125
  /// should be percent-escaped in the query string.
126
  static let sbURLQueryAllowed: CharacterSet = {
2✔
127
    let generalDelimitersToEncode = ":#[]@"  // does not include "?" or "/" due to RFC 3986 - Section 3.4
2✔
128
    let subDelimitersToEncode = "!$&'()*+,;="
2✔
129
    let encodableDelimiters = CharacterSet(
2✔
130
      charactersIn: "\(generalDelimitersToEncode)\(subDelimitersToEncode)")
2✔
131

2✔
132
    return CharacterSet.urlQueryAllowed.subtracting(encodableDelimiters)
2✔
133
  }()
2✔
134
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc