angular-sanitize: how not to sanitize Nothern languages letters (with umlauts)?
Asked Answered
F

0

6

We have found that angular-sanitize "sanitizes" the Nordic alphabet's characters and makes them into HTML entities. So every time you input ä character in INPUT and $sanitize your input, you end up with sanitized string that gets these characters replaced by something else (&auml ;), which corrupts the input, as later I'd like display that string or send it to server. And it appears that user entered "&auml" not "ä". We work in UTF8 as usual, so we do not need this.

Presently we have a solution workaround like this (app is our angular application):

app.config(function($provide){

    // Prevent $sanitize from converting nordic special characters (ö, ä, å) into HTML entities
    // ----------------------------------------------------------------------------------------
    // We don't have need for sanitizing umlauts. 

    $provide.decorator("$sanitize", function($delegate, $log){
        return function(text, target){

            var result = $delegate(text, target);

            result = result
                .replace(/ä|ä/g, 'ä')
                .replace(/Ä|Ä/g, 'Ä')
                .replace(/ö|ö/g, 'ö')
                .replace(/Ö|Ö/g, 'Ö')
                .replace(/å|å/g, 'å')
                .replace(/Å|Å/g, 'Å');

            return result;
        };
    });
});

However I suspect that there might be a nicer way to achieve this by telling $sanitize some options. I appreciate suggestions how to do it better way.

Frontality answered 27/11, 2015 at 14:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.