From e9305f40ee1730c163fe05ede08cbe4e172af60f Mon Sep 17 00:00:00 2001 From: buliabyak Date: Fri, 8 Aug 2008 02:47:03 +0000 Subject: [PATCH] patch from bug 244940 --- src/text-context.cpp | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) diff --git a/src/text-context.cpp b/src/text-context.cpp index 0865e06cb..5e0e1ee8e 100644 --- a/src/text-context.cpp +++ b/src/text-context.cpp @@ -1322,10 +1322,36 @@ sp_text_paste_inline(SPEventContext *ec) // there is an active text object in this context, or a new object was just created Glib::RefPtr refClipboard = Gtk::Clipboard::get(); - Glib::ustring const text = refClipboard->wait_for_text(); - - if (!text.empty()) { - + Glib::ustring const clip_text = refClipboard->wait_for_text(); + + if (!clip_text.empty()) { + // Fix for 244940 + // The XML standard defines the following as valid characters + // (Extensible Markup Language (XML) 1.0 (Fourth Edition) paragraph 2.2) + // char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] + // Since what comes in off the paste buffer will go right into XML, clean + // the text here. + Glib::ustring text(clip_text); + Glib::ustring::iterator itr = text.begin(); + gunichar paste_string_uchar; + + while(itr != text.end()) + { + paste_string_uchar = *itr; + + // Make sure we don't have a control character. We should really check + // for the whole range above... Add the rest of the invalid cases from + // above if we find additional issues + if(paste_string_uchar >= 0x00000020 || + paste_string_uchar == 0x00000009 || + paste_string_uchar == 0x0000000A || + paste_string_uchar == 0x0000000D) { + itr++; + } else { + itr = text.erase(itr); + } + } + if (!tc->text) { // create text if none (i.e. if nascent_object) sp_text_context_setup_text(tc); tc->nascent_object = 0; // we don't need it anymore, having created a real -- 2.30.2