diff --git a/internal_packages/composer/lib/contenteditable-component.cjsx b/internal_packages/composer/lib/contenteditable-component.cjsx index 15e66fbc8..5658f7f3f 100644 --- a/internal_packages/composer/lib/contenteditable-component.cjsx +++ b/internal_packages/composer/lib/contenteditable-component.cjsx @@ -339,7 +339,7 @@ class ContenteditableComponent extends React.Component menu.append(new MenuItem({ label: 'Copy', click:copy})) menu.append(new MenuItem({ label: 'Paste', click:paste})) menu.popup(remote.getCurrentWindow()) - + _onMouseDown: (event) => @_mouseDownEvent = event @_mouseHasMoved = false @@ -723,6 +723,14 @@ class ContenteditableComponent extends React.Component # https://regex101.com/r/gF6bF4/4 inputText = inputText.replace(/(\s*){3,}/g, "

") + # We never want to keep leading and trailing , since the user + # would have started a new paragraph themselves if they wanted space + # before what they paste. + # BAD: "

begins at
12AM

" => "

begins at
12AM

" + # Better: "

begins at
12AM

" => "begins at
12" + inputText = inputText.replace(/^(
)+/, '') + inputText = inputText.replace(/(
)+$/, '') + return inputText diff --git a/internal_packages/composer/spec/contenteditable-component-spec.cjsx b/internal_packages/composer/spec/contenteditable-component-spec.cjsx index 3bc4af042..da3d49255 100644 --- a/internal_packages/composer/spec/contenteditable-component-spec.cjsx +++ b/internal_packages/composer/spec/contenteditable-component-spec.cjsx @@ -97,16 +97,42 @@ describe "ContenteditableComponent", -> { in: " Foo Bar
Baz
" # Strip bad tags - sanitizedAsHTML: " Foo Bar Baz
" + sanitizedAsHTML: " Foo Bar Baz" # HTML encode tags for literal display sanitizedAsPlain: "<style>Yo</style> Foo Bar <div>Baz</div>" - } + }, { in: " Yo < script>Boo! < / script >" # Strip non white-list tags and encode malformed ones. sanitizedAsHTML: " Yo < script>Boo! < / script >" # HTML encode tags for literal display sanitizedAsPlain: "<script>Bah</script> Yo < script>Boo! < / script >" + }, + { + in: """ + + + + + + + + + + + + + + """ + # Strip non white-list tags and encode malformed ones. + sanitizedAsHTML: "" + # HTML encode tags for literal display + sanitizedAsPlain: "<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="1265.21">
<style type="text/css">
li.li1 {margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Helvetica}
ul.ul1 {list-style-type: disc}
</style>
</head>
<body>
<ul class="ul1">
<li class="li1"><b>Packet pickup: </b>I'll pick up my packet at some point on Saturday at Fort Mason. Let me know if you'd like me to get yours. I'll need a photo of your ID and your confirmation number. Also, shirt color preference, I believe. Gray or black? Can't remember...</li>
</ul>
</body>
</html>" } ]