|
1 | 1 | // --- stubs ---
|
2 | 2 |
|
3 | 3 | class NSObject { }
|
4 |
| -class NSAttributedString: NSObject {} |
5 |
| -class UIResponder: NSObject {} |
6 |
| -class UIView: UIResponder {} |
7 |
| -class UIControl: UIView {} |
| 4 | + |
| 5 | +struct _NSRange { } |
| 6 | + |
| 7 | +typealias NSRange = _NSRange |
| 8 | + |
| 9 | +class NSAttributedString: NSObject { } |
| 10 | + |
| 11 | +class UIResponder: NSObject { } |
| 12 | + |
| 13 | +class UIView: UIResponder { } |
| 14 | + |
| 15 | +class UIControl: UIView { } |
| 16 | + |
| 17 | +class UITextRange : NSObject { |
| 18 | +} |
| 19 | + |
| 20 | +protocol UITextInput { |
| 21 | + func text(in range: UITextRange) -> String? |
| 22 | + |
| 23 | + func shouldChangeText(in range: UITextRange, replacementText text: String) -> Bool |
| 24 | +} |
| 25 | + |
8 | 26 | class UITextField: UIControl {
|
9 | 27 | var text: String? {
|
10 | 28 | get { nil }
|
11 | 29 | set { }
|
12 | 30 | }
|
| 31 | + |
13 | 32 | var attributedText: NSAttributedString? {
|
14 | 33 | get { nil }
|
15 | 34 | set { }
|
16 | 35 | }
|
| 36 | + |
17 | 37 | var placeholder: String? {
|
18 | 38 | get { nil }
|
19 | 39 | set { }
|
20 | 40 | }
|
21 | 41 | }
|
| 42 | + |
22 | 43 | class UISearchTextField : UITextField {
|
23 | 44 | }
|
24 | 45 |
|
| 46 | +protocol UITextFieldDelegate { |
| 47 | + func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool |
| 48 | +} |
| 49 | + |
25 | 50 | // --- tests ---
|
26 | 51 |
|
27 |
| -func testUITextField(textField: UITextField, searchTextField: UISearchTextField) { |
| 52 | +func sink(arg: Any) { } |
| 53 | + |
| 54 | +class MyTextInput : UITextInput { |
| 55 | + func text(in range: UITextRange) -> String? { return nil } |
| 56 | + func harmless(in range: UITextRange) -> String? { return nil } |
| 57 | + |
| 58 | + func shouldChangeText(in range: UITextRange, replacementText text: String) -> Bool { // $ MISSING: source=local |
| 59 | + sink(arg: text) // $ MISSING: tainted= |
| 60 | + |
| 61 | + return true |
| 62 | + } |
| 63 | +} |
| 64 | + |
| 65 | +class MyUITextFieldDelegate : UITextFieldDelegate { |
| 66 | + func textField(_ textField: UITextField, shouldChangeCharactersIn range: NSRange, replacementString string: String) -> Bool { // $ MISSING: source=local |
| 67 | + sink(arg: string) // $ MISSING: tainted= |
| 68 | + |
| 69 | + return true |
| 70 | + } |
| 71 | +} |
| 72 | + |
| 73 | +func test(textField: UITextField, searchTextField: UISearchTextField, myTextInput: MyTextInput, range: UITextRange) { |
28 | 74 | _ = textField.text // $ source=local
|
29 | 75 | _ = textField.attributedText // $ source=local
|
30 | 76 | _ = textField.placeholder // GOOD (not input)
|
31 | 77 | _ = textField.text?.uppercased() // $ source=local
|
32 | 78 | _ = searchTextField.text // $ source=local
|
| 79 | + |
| 80 | + _ = myTextInput.text(in: range)! // $ MISSING: source=local |
| 81 | + _ = myTextInput.harmless(in: range)! // GOOD (not input) |
33 | 82 | }
|
0 commit comments