From 23ea4b673968420eb2489d54ebbc28d8b2849b16 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Mon, 4 Dec 2017 14:21:08 -0500 Subject: [PATCH] FIX: don't create featured link if title includes more than a url --- .../discourse/components/composer-title.js.es6 | 2 +- .../acceptance/composer-topic-links-test.js.es6 | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/discourse/components/composer-title.js.es6 b/app/assets/javascripts/discourse/components/composer-title.js.es6 index f6816fb302f..2a828a9483a 100644 --- a/app/assets/javascripts/discourse/components/composer-title.js.es6 +++ b/app/assets/javascripts/discourse/components/composer-title.js.es6 @@ -128,7 +128,7 @@ export default Ember.Component.extend({ @computed('composer.title', 'composer.titleLength') isAbsoluteUrl(title, titleLength) { - return titleLength > 0 && /^(https?:)?\/\/[\w\.\-]+/i.test(title); + return titleLength > 0 && /^(https?:)?\/\/[\w\.\-]+/i.test(title) && !/\s/.test(title); }, bodyIsDefault() { diff --git a/test/javascripts/acceptance/composer-topic-links-test.js.es6 b/test/javascripts/acceptance/composer-topic-links-test.js.es6 index 515e01f111b..6f55248803e 100644 --- a/test/javascripts/acceptance/composer-topic-links-test.js.es6 +++ b/test/javascripts/acceptance/composer-topic-links-test.js.es6 @@ -63,4 +63,15 @@ QUnit.test("link is longer than max title length", assert => { assert.ok(exists('.d-editor-textarea-wrapper .popup-tip.good'), 'the body is now good'); assert.equal(find('.title-input input').val(), "An interesting article", "title is from the oneboxed article"); }); -}); \ No newline at end of file +}); + +QUnit.test("onebox with title but extra words in title field", assert => { + visit("/"); + click('#create-topic'); + fillIn('#reply-title', "http://www.example.com/has-title.html test"); + andThen(() => { + assert.equal(find('.d-editor-preview').html().trim().indexOf('onebox'), -1, "onebox preview doesn't show"); + assert.equal(find('.d-editor-input').val().length, 0, "link isn't put into the post"); + assert.equal(find('.title-input input').val(), "http://www.example.com/has-title.html test", "title is unchanged"); + }); +});