#314 Ignoring accents for string arguments in the filter fails on Windows

v4.8.1
closed
nobody
None
5
2013-08-27
2012-12-14
Javier Paniza
No

Run ColorTest.testIgnoreAccentsForStringArgumentsInTheFilter() from a Windows.

Maybe it's not Windows but the different charset.

Discussion

  • Javier Paniza
    Javier Paniza
    2013-08-20

    The problem is that we use special characters in source code (the ones for accents) that are transformed when source code is moved between machines with different encodings.

    The solution is changing the characters by corresponding the unicode code:

    á -> \u00E1
    é -> \u00E9
    í -> \u00ED
    ó -> \u00F3
    ú -> \u00FA
    
    Á -> \u00C1
    É -> \u00C9
    Í -> \u00CD
    Ó -> \u00D3
    Ú -> \u00DA
    

    This change must be done in the translateSQLFunction() method of ModelMapping:

    public String translateSQLFunction(String column){
        if (supportsTranslateFunction()) {
            return "translate(" + column + 
                ",'aeiouAEIOU','\u00E1\u00E9\u00ED\u00F3\u00FA\u00C1\u00C9\u00CD\u00D3\u00DA')"; 
        }
        return 
            "replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(" + 
            column + 
            ", '\u00DA', 'U'), '\u00FA', 'u'), '\u00D3', 'O'), '\u00F3', 'o'), '\u00CD', 'I'), " +
            "'\u00ED', 'i'), '\u00C9', 'E'), '\u00E9', 'e'), '\u00C1', 'A'), '\u00E1', 'a')";           
    }
    

    And the removeAccents() method of Strings:

    public static String removeAccents(String value){ 
        return value.
                replace("\u00E1", "a").replace("\u00C1", "A").
                replace("\u00E9", "e").replace("\u00C9", "E").
                replace("\u00ED", "i").replace("\u00CD", "I").
                replace("\u00F3", "o").replace("\u00D3", "O").
                replace("\u00FA", "u").replace("\u00DA", "U");      
    }
    

    Moreover, the ColorTest.testIgnoreAccentsForStringArgumentsInTheFilter() does not take into account searching with accent, that can fail if we fix only one of the above method.

     
  • Javier Paniza
    Javier Paniza
    2013-08-27

    • status: open --> closed
    • Group: v1.0_(example) --> v4.8.1