|
| 1 | + |
| 2 | +// --- stubs --- |
| 3 | + |
| 4 | +protocol View { |
| 5 | +} |
| 6 | + |
| 7 | +struct Binding<Value> { |
| 8 | +} |
| 9 | + |
| 10 | +@propertyWrapper |
| 11 | +struct State<Value> { // an @State |
| 12 | + var wrappedValue: Value |
| 13 | + var projectedValue: Binding<Value> { get { return 0 as! Binding<Value> } } // what you get with `$` |
| 14 | +} |
| 15 | + |
| 16 | +struct LocalizedStringKey : ExpressibleByStringLiteral { |
| 17 | + typealias StringLiteralType = String |
| 18 | + |
| 19 | + init(stringLiteral value: Self.StringLiteralType) { |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +struct Label<Title, Icon> : View where Title : View, Icon : View { |
| 24 | +} |
| 25 | + |
| 26 | +struct Text : View { |
| 27 | +} |
| 28 | + |
| 29 | +struct TextField<Label> : View where Label : View { |
| 30 | + init(_ titleKey: LocalizedStringKey, text: Binding<String>) where Label == Text { } |
| 31 | +} |
| 32 | + |
| 33 | +struct SecureField<Label> : View where Label : View { |
| 34 | + init(_ titleKey: LocalizedStringKey, text: Binding<String>, prompt: Text?) where Label == Text { } |
| 35 | +} |
| 36 | + |
| 37 | +struct TextEditor : View { |
| 38 | + init(text: Binding<String>) { } |
| 39 | +} |
| 40 | + |
| 41 | +struct SubmitTriggers { |
| 42 | + init(rawValue: UInt) { |
| 43 | + self.rawValue = rawValue |
| 44 | + } |
| 45 | + |
| 46 | + var rawValue: UInt |
| 47 | + |
| 48 | + static let text = SubmitTriggers(rawValue: 1) |
| 49 | +} |
| 50 | + |
| 51 | +extension View { |
| 52 | + func onSubmit( |
| 53 | + of triggers: SubmitTriggers = .text, |
| 54 | + _ action: @escaping (() -> Void) |
| 55 | + ) -> some View { |
| 56 | + return self |
| 57 | + } |
| 58 | +} |
| 59 | + |
| 60 | +// --- tests --- |
| 61 | + |
| 62 | +func sink(arg: Any) { } |
| 63 | + |
| 64 | +func mkHarmlessBinding(text: Binding<String>) { } |
| 65 | + |
| 66 | +struct MyStruct { |
| 67 | + @State var input: String = "default value" |
| 68 | + @State var harmless: String = "default value" |
| 69 | + @State var harmless2: String = "default value" |
| 70 | + |
| 71 | + var myView1: some View { |
| 72 | + TextField("title", text: $input) |
| 73 | + .onSubmit { |
| 74 | + sink(arg: input) // $ MISSING: tainted |
| 75 | + sink(arg: harmless) |
| 76 | + mkHarmlessBinding(text: $harmless2) |
| 77 | + sink(arg: harmless2) |
| 78 | + } |
| 79 | + } |
| 80 | + |
| 81 | + @State var secureInput: String = "default value" |
| 82 | + |
| 83 | + var myView2: some View { |
| 84 | + SecureField("title", text: $secureInput, prompt: nil) |
| 85 | + .onSubmit { |
| 86 | + sink(arg: secureInput) // $ MISSING: tainted |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + @State var longInput: String = "default value" |
| 91 | + |
| 92 | + var myView3: some View { |
| 93 | + TextEditor(text: $longInput) |
| 94 | + .onSubmit { |
| 95 | + sink(arg: longInput) // $ MISSING: tainted |
| 96 | + } |
| 97 | + } |
| 98 | +} |
0 commit comments