How to check invalid characters passed to installdir

Comments

1 comment

  • Avatar
    wojciechka

    This depends on what your invalid characters are. Is this caused by the application not handling certain letters (i.e. Unicode) in path correctly. If so, the recommended approach is to create a regular expression that throws away invalid values:

    <throwError>
        <text>Invalid value</text>
        <ruleList>
            <regExMatch>
                <logic>matches</logic>
                <pattern>[\u0000-\u001f\u0080-\uffff]</pattern>
                <text>${installdir}</text>
            </regExMatch>
        </ruleList>
    </throwError>
    

    The above will catch any character that may be illegal, including Unicode characters. This may cause issues for some OSes where paths may include non-latin characters, though.

    Another option is to create a regular expression that checks that the path matches a specific pattern or only uses acceptable characters. For example:

    <throwError>
        <text>Invalid value</text>
        <ruleList>
            <regExMatch>
                <logic>does_not_match</logic>
                <pattern>^[\u0020-\u003fA-Za-z:\\]+$</pattern>
                <text>${installdir}</text>
            </regExMatch>
        </ruleList>
    </throwError>
    

    This only accepts basic ascii characters, slash and back slash.

Please sign in to leave a comment.