diff --git a/core/src/display_object/edit_text.rs b/core/src/display_object/edit_text.rs index 38eed63f63e0..5fa81ef484c1 100644 --- a/core/src/display_object/edit_text.rs +++ b/core/src/display_object/edit_text.rs @@ -1399,7 +1399,8 @@ impl<'gc> EditText<'gc> { } } TextControlCode::Paste => { - let mut text = context.ui.clipboard_content(); + let text = context.ui.clipboard_content(); + let mut text = self.0.read().restrict.filter_allowed(&text); if text.len() > self.available_chars() && self.available_chars() > 0 { text = text[0..self.available_chars()].to_owned(); @@ -2532,4 +2533,14 @@ impl EditTextRestrict { None } } + + pub fn filter_allowed(&self, text: &str) -> String { + let mut filtered = String::with_capacity(text.len()); + for c in text.chars() { + if let Some(c) = self.to_allowed(c) { + filtered.push(c); + } + } + filtered + } } diff --git a/tests/tests/swfs/avm1/edittext_restrict_paste/input.json b/tests/tests/swfs/avm1/edittext_restrict_paste/input.json new file mode 100644 index 000000000000..139ab21a9f2b --- /dev/null +++ b/tests/tests/swfs/avm1/edittext_restrict_paste/input.json @@ -0,0 +1,17 @@ +[ + { "type": "SetClipboardText", "text": "abc" }, + { "type": "TextControl", "code": "Paste" }, + { "type": "KeyDown", "key_code": 27 }, + { "type": "SetClipboardText", "text": "aaa" }, + { "type": "TextControl", "code": "Paste" }, + { "type": "KeyDown", "key_code": 27 }, + { "type": "SetClipboardText", "text": "aAbBcCdD" }, + { "type": "TextControl", "code": "Paste" }, + { "type": "KeyDown", "key_code": 27 }, + { "type": "SetClipboardText", "text": "aaaBBCC" }, + { "type": "TextControl", "code": "Paste" }, + { "type": "KeyDown", "key_code": 27 }, + { "type": "SetClipboardText", "text": "abcabc" }, + { "type": "TextControl", "code": "Paste" }, + { "type": "KeyDown", "key_code": 27 } +] diff --git a/tests/tests/swfs/avm1/edittext_restrict_paste/output.txt b/tests/tests/swfs/avm1/edittext_restrict_paste/output.txt new file mode 100644 index 000000000000..45d26d15fc5b --- /dev/null +++ b/tests/tests/swfs/avm1/edittext_restrict_paste/output.txt @@ -0,0 +1,5 @@ +Text: 'bc' +Text: '' +Text: 'bbc' +Text: 'bbc' +Text: 'bcb' diff --git a/tests/tests/swfs/avm1/edittext_restrict_paste/test.as b/tests/tests/swfs/avm1/edittext_restrict_paste/test.as new file mode 100644 index 000000000000..caa3a15eb14c --- /dev/null +++ b/tests/tests/swfs/avm1/edittext_restrict_paste/test.as @@ -0,0 +1,13 @@ +var listener = new Object(); +listener.onKeyDown = function() { + if (Key.getCode() == 27) { + trace("Text: '" + text.text + "'"); + text.text = ""; + } +}; +Key.addListener(listener); + +text.restrict = "bc"; +text.maxChars = 3; + +Selection.setFocus(text); diff --git a/tests/tests/swfs/avm1/edittext_restrict_paste/test.swf b/tests/tests/swfs/avm1/edittext_restrict_paste/test.swf new file mode 100644 index 000000000000..edc0137dd0f3 Binary files /dev/null and b/tests/tests/swfs/avm1/edittext_restrict_paste/test.swf differ diff --git a/tests/tests/swfs/avm1/edittext_restrict_paste/test.toml b/tests/tests/swfs/avm1/edittext_restrict_paste/test.toml new file mode 100644 index 000000000000..dbee897f5863 --- /dev/null +++ b/tests/tests/swfs/avm1/edittext_restrict_paste/test.toml @@ -0,0 +1 @@ +num_frames = 1