• Resolved hulgupta

    (@hulgupta)


    Hi folks,

    The documentation and this forum states that if you escape your commas with \, the plugin will import properly.

    Unfortunately, the JS that parses the terms is using .replace, which only replaces the first instance of a matching string… _unless_ you regular expressions are employed.

    So, to fix this, I made a change to the code in inspector.

    I changed self._processTerms in ‘bulk-term-generator-admin.js’ from:

            self._processTerms = function( terms ){
    
                var processedTerms = [];
    
                // Seperate terms by comma, and trim the white space
                for (var i = 0; i < terms.length; i++) {
                    console.log(terms[i].match(/([^,]+),([^,]+),(.*)/));
                    var terms_array = terms[i].replace( '\\,', '{COMMA}' ).split(',').map(function(v){return v.replace('{COMMA}',',');});
                    terms_array = $.map(terms_array, $.trim);
                    processedTerms.push(terms_array);
                }
    
                return processedTerms;
            };

    to:

            self._processTerms = function( terms ){
    
                var processedTerms = [];
    
                // Seperate terms by comma, and trim the white space
                for (var i = 0; i < terms.length; i++) {
                    console.log(terms[i].match(/([^,]+),([^,]+),(.*)/));
                    var terms_array = terms[i].replace( /\\,/g, '{COMMA}' ).split(',').map(function(v){return v.replace( /{COMMA}/g,',');});
                    terms_array = $.map(terms_array, $.trim);
                    processedTerms.push(terms_array);
                }
    
                return processedTerms;
            };

    This just changes the string in the 2 replace calls from strings to global regular expressions.

  • The topic ‘Comma Escaping only Escapes First Comma’ is closed to new replies.