From 3eaf2829e8f7ea0dd5967ea537f4fcd8ccf37679 Mon Sep 17 00:00:00 2001 From: Prateek Saxena Date: Fri, 2 Jan 2015 17:01:12 +0530 Subject: [PATCH] renderer.article: Remove leading spaces before brackets Bug: T69225 Change-Id: I83f79fa0ebd19bea6ed7ea266cece0778210adb2 --- resources/ext.popups.renderer.article.js | 4 ++++ tests/qunit/ext.popups.renderer.article.test.js | 8 +++++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/resources/ext.popups.renderer.article.js b/resources/ext.popups.renderer.article.js index 7d100bafa..9f2c33b00 100644 --- a/resources/ext.popups.renderer.article.js +++ b/resources/ext.popups.renderer.article.js @@ -210,6 +210,10 @@ continue; } if ( level === 0 ) { + // Remove leading spaces before brackets + if ( ch === ' ' && string.charAt( i + 1 ) === '(' ) { + continue; + } newString += ch; } } diff --git a/tests/qunit/ext.popups.renderer.article.test.js b/tests/qunit/ext.popups.renderer.article.test.js index 81e58bd64..9d1622e5f 100644 --- a/tests/qunit/ext.popups.renderer.article.test.js +++ b/tests/qunit/ext.popups.renderer.article.test.js @@ -2,7 +2,7 @@ QUnit.module( 'ext.popups' ); QUnit.test( 'render.article.getProcessedElements', function ( assert ) { - QUnit.expect( 11 ); + QUnit.expect( 12 ); function test ( extract, title, expected, msg ) { var $div = $( '
' ).append( @@ -59,6 +59,12 @@ 'Extract with unbalanced parentheses' ); + test( + 'Vappu (born August 7), also known as Lexy', 'Vappu', + 'Vappu, also known as Lexy', + 'Spaces around bracketed text should be removed' + ); + test( 'Epic XSS is epic', 'Epic XSS', 'Epic XSS <script>alert</script> is epic',