Ticket #2728 (confirmed Bug)

Opened 5 years ago

Last modified 13 months ago

String.prototype.Trim should also trim unicode ideographic space

Reported by: thiloplanz Owned by:
Priority: Normal Milestone:
Component: General Version:
Keywords: Cc:

Description

String.prototype.Trim (defined in fckjscoreextensions.js) should also remove the Unicode "Ideographic Space" (U+3000), which is used in Japanese.

String.prototype.Trim = function()
{
        // We are not using \s because we don't want "non-breaking spaces to be caught".
        return this.replace( /(^[ \t\n\r\u3000]*)|([ \t\n\r\u3000]*$)/g, '' ) ;
}

String.prototype.LTrim = function()
{
        // We are not using \s because we don't want "non-breaking spaces to be caught".
        return this.replace( /^[ \t\n\r\u3000]*/g, '' ) ;
}

String.prototype.RTrim = function()
{
        // We are not using \s because we don't want "non-breaking spaces to be caught".
        return this.replace( /[ \t\n\r\u3000]*$/g, '' ) ;
}

Change History

comment:1 Changed 5 years ago by mosipov

There are several whitespace defitions, the base whitespace def in Unicode is here but most languages restrict to ASCII whitespace. So either you restrict to ASCII or strip all Unicode whitespace.

comment:2 Changed 5 years ago by thiloplanz

I am not sure we want to strip all Unicode whitespace, for example the "non-breaking spaces" mentioned in the comment in the code need to be preserved. The various types would need to be reviewed one by one, by someone who actually uses them.

For Japanese users, U+3000 is commonly used and treated the same as "regular" space, with an expectation that it should also be trimmed.

comment:3 Changed 5 years ago by thiloplanz

  • Summary changed from String.prototype.Trim should also trim unicode two-byte whitespace to String.prototype.Trim should also trim unicode ideographic space

comment:4 Changed 13 months ago by Reinmar

  • Status changed from new to confirmed

The ECMAScript 5's String#trim method replaces /\s/ and this pattern includes U+3000 character. I think that CKEditor should do that too.

https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/Trim

Note: See TracTickets for help on using tickets.
© 2003 – 2012 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy