Skip to content

Commit 2882286

Browse files
committed
Swift: Test taint sources for NSString.
1 parent 9f73407 commit 2882286

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
2+
// --- stubs ---
3+
4+
struct URL {
5+
init?(string: String) {}
6+
}
7+
8+
class NSObject {
9+
}
10+
11+
class NSString : NSObject {
12+
init(string aString: String) {}
13+
14+
convenience init?(contentsOfFile path: String) { self.init(string: "") }
15+
convenience init(contentsOfFile path: String, encoding enc: UInt) throws { self.init(string: "") }
16+
convenience init(contentsOfFile path: String, usedEncoding enc: UnsafeMutablePointer<UInt>?) throws { self.init(string: "") }
17+
convenience init?(contentsOf url: URL) { self.init(string: "") }
18+
convenience init(contentsOf url: URL, encoding enc: UInt) throws { self.init(string: "") }
19+
convenience init(contentsOf url: URL, usedEncoding enc: UnsafeMutablePointer<UInt>?) throws { self.init(string: "") }
20+
21+
class func string(withContentsOfFile path: String) -> Any? { return nil }
22+
class func string(withContentsOf url: URL) -> Any? { return nil }
23+
}
24+
25+
// --- tests ---
26+
27+
func testNSStrings() {
28+
do
29+
{
30+
let path = "file.txt"
31+
let string1 = try NSString(contentsOfFile: path) // SOURCE
32+
let string2 = try NSString(contentsOfFile: path, encoding: 0) // SOURCE
33+
let string3 = try NSString(contentsOfFile: path, usedEncoding: nil) // SOURCE
34+
let string4 = NSString.string(withContentsOfFile: path) // SOURCE
35+
36+
let url = URL(string: "http://example.com/")!
37+
let string5 = try NSString(contentsOf: url) // SOURCE
38+
let string6 = try NSString(contentsOf: url, encoding: 0) // SOURCE
39+
let string7 = try NSString(contentsOf: url, usedEncoding: nil) // SOURCE
40+
let string8 = NSString.string(withContentsOf: url) // SOURCE
41+
} catch {
42+
// ...
43+
}
44+
}

0 commit comments

Comments
 (0)