From 00c5ec202ccde20eace5c867578262efa5b69844 Mon Sep 17 00:00:00 2001 From: Anthony Ramine Date: Tue, 31 Mar 2020 14:35:37 +0200 Subject: Make LayoutHTMLTextAreaElementHelpers::value_for_layout safe --- components/script/dom/htmltextareaelement.rs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'components/script/dom/htmltextareaelement.rs') diff --git a/components/script/dom/htmltextareaelement.rs b/components/script/dom/htmltextareaelement.rs index 8ee42bc2c86..e3721a78213 100755 --- a/components/script/dom/htmltextareaelement.rs +++ b/components/script/dom/htmltextareaelement.rs @@ -56,8 +56,7 @@ pub struct HTMLTextAreaElement { } pub trait LayoutHTMLTextAreaElementHelpers { - #[allow(unsafe_code)] - unsafe fn value_for_layout(self) -> String; + fn value_for_layout(self) -> String; #[allow(unsafe_code)] unsafe fn selection_for_layout(self) -> Option>; #[allow(unsafe_code)] @@ -67,19 +66,19 @@ pub trait LayoutHTMLTextAreaElementHelpers { } impl LayoutHTMLTextAreaElementHelpers for LayoutDom<'_, HTMLTextAreaElement> { - #[allow(unrooted_must_root)] #[allow(unsafe_code)] - unsafe fn value_for_layout(self) -> String { - let text = (*self.unsafe_get()) - .textinput - .borrow_for_layout() - .get_content(); - if text.is_empty() { - (*self.unsafe_get()) - .placeholder + fn value_for_layout(self) -> String { + let text = unsafe { + self.unsafe_get() + .textinput .borrow_for_layout() - .replace("\r\n", "\n") - .replace("\r", "\n") + .get_content() + }; + if text.is_empty() { + let placeholder = unsafe { self.unsafe_get().placeholder.borrow_for_layout() }; + // FIXME(nox): Would be cool to not allocate a new string if the + // placeholder is single line, but that's an unimportant detail. + placeholder.replace("\r\n", "\n").replace("\r", "\n").into() } else { text.into() } -- cgit v1.2.3