FIX: allow pasting links into title field that are longer than the max title length

This commit is contained in:
Neil Lalonde 2017-05-18 12:32:35 -04:00
parent 29755be139
commit dbb814ec6a
4 changed files with 22 additions and 3 deletions

View File

@ -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); }

View File

@ -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}}

View File

@ -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");
});
});

View File

@ -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"},