From dbb814ec6a61fa1ca4420196dc74af05e4e40662 Mon Sep 17 00:00:00 2001 From: Neil Lalonde Date: Thu, 18 May 2017 12:32:35 -0400 Subject: [PATCH] FIX: allow pasting links into title field that are longer than the max title length --- .../discourse/components/composer-title.js.es6 | 7 +++++++ .../templates/components/composer-title.hbs | 2 +- .../acceptance/composer-topic-links-test.js.es6 | 14 +++++++++++++- test/javascripts/helpers/create-pretender.js.es6 | 2 +- 4 files changed, 22 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/components/composer-title.js.es6 b/app/assets/javascripts/discourse/components/composer-title.js.es6 index 0c173bdd0c3..2e37da138ee 100644 --- a/app/assets/javascripts/discourse/components/composer-title.js.es6 +++ b/app/assets/javascripts/discourse/components/composer-title.js.es6 @@ -31,6 +31,13 @@ export default Ember.Component.extend({ } }, + @computed('watchForLink') + titleMaxLength() { + // maxLength gets in the way of pasting long links, so don't use it if featured links are allowed. + // Validation will display a message if titles are too long. + return this.get('watchForLink') ? null : this.siteSettings.max_topic_title_length; + }, + @observes('composer.titleLength', 'watchForLink') _titleChanged() { if (this.get('composer.titleLength') === 0) { this.set('autoPosted', false); } diff --git a/app/assets/javascripts/discourse/templates/components/composer-title.hbs b/app/assets/javascripts/discourse/templates/components/composer-title.hbs index 7da7bb6ec38..f4a824f57aa 100644 --- a/app/assets/javascripts/discourse/templates/components/composer-title.hbs +++ b/app/assets/javascripts/discourse/templates/components/composer-title.hbs @@ -1,7 +1,7 @@ {{text-field value=composer.title tabindex="2" id="reply-title" - maxLength=siteSettings.max_topic_title_length + maxLength=titleMaxLength placeholderKey=composer.titlePlaceholder disabled=composer.loading}} diff --git a/test/javascripts/acceptance/composer-topic-links-test.js.es6 b/test/javascripts/acceptance/composer-topic-links-test.js.es6 index c6bede46ffe..3876fcc5cc8 100644 --- a/test/javascripts/acceptance/composer-topic-links-test.js.es6 +++ b/test/javascripts/acceptance/composer-topic-links-test.js.es6 @@ -3,7 +3,8 @@ import { acceptance } from "helpers/qunit-helpers"; acceptance("Composer topic featured links", { loggedIn: true, settings: { - topic_featured_link_enabled: true + topic_featured_link_enabled: true, + max_topic_title_length: 80 } }); @@ -52,3 +53,14 @@ test("ignore internal links", () => { equal(find('.title-input input').val(), title, "title is unchanged"); }); }); + +test("link is longer than max title length", () => { + visit("/"); + click('#create-topic'); + fillIn('#reply-title', "http://www.example.com/has-title-and-a-url-that-is-more-than-80-characters-because-thats-good-for-seo-i-guess.html"); + andThen(() => { + ok(find('.d-editor-preview').html().trim().indexOf('onebox') > 0, "it pastes the link into the body and previews it"); + ok(exists('.d-editor-textarea-wrapper .popup-tip.good'), 'the body is now good'); + equal(find('.title-input input').val(), "An interesting article", "title is from the oneboxed article"); + }); +}); diff --git a/test/javascripts/helpers/create-pretender.js.es6 b/test/javascripts/helpers/create-pretender.js.es6 index 8ae140d9224..ef7b3ffec67 100644 --- a/test/javascripts/helpers/create-pretender.js.es6 +++ b/test/javascripts/helpers/create-pretender.js.es6 @@ -335,7 +335,7 @@ export default function() { this.delete('/admin/badges/:id', success); this.get('/onebox', request => { - if (request.queryParams.url === 'http://www.example.com/has-title.html') { + if (request.queryParams.url.startsWith('http://www.example.com/has-title')) { return [ 200, {"Content-Type": "application/html"},