Repository: aws-cloudformation/cfn-lint

Issue:
E0000 found unknown escape character '/'
*cfn-lint version: `0.29.2`*

*Description of issue.*

Using a regex pattern in a JSON cfn template fails linting with `E000 found unknown escape character '/'`

This appears to be a duplicate of #727 but the fix applied as part of that PR doesn't seem to be working in this case.

The JSON snippet that's causing issues is:
```
"AppIdRegexPattern": {
            "Type": "AWS::WAFv2::RegexPatternSet",
            "Properties": {
                "Name": "x-mitel-app-regex",
                "Description": "Handles validating an appropriate Mitel app identifier is present, and the app is provided",
                "Scope": "REGIONAL",
                "RegularExpressionList": [
                    "^app=[a-z-\\.0-9]+\/[0-9.a-z-]+;"
                ]
            }
        }
```

Here's the debug output from linting the file

```
$ cfn-lint cloudlink-waf.template --debug
2020-03-31 14:24:27,769 - cfnlint - DEBUG - Looking for CFLINTRC before attempting to load
2020-03-31 14:24:27,770 - cfnlint - DEBUG - Validating User CFNLINTRC
2020-03-31 14:24:27,771 - cfnlint - DEBUG - Validating CFNLINTRC config with given JSONSchema
2020-03-31 14:24:27,772 - cfnlint - DEBUG - Schema used: {'$id': 'https://github.com/aws-cloudformation/cfn-python-lint/blob/master/src/cfnlint/data/CfnLintCli/config/schema.json', '$schema': 'http://json-schema.org/draft-07/schema#', 'description': 'CFNLINTRC configuration schema', 'title': 'CFNLINTRC JSON Schema', 'type': 'object', 'additionalProperties': False, 'properties': {'append_rules': {'description': 'Location of directories to append rules from', 'items': {'type': 'string'}, 'type': 'array'}, 'ignore_checks': {'description': 'List of checks to ignore', 'items': {'type': 'string'}, 'type': 'array'}, 'include_checks': {'description': 'List of checks to include', 'items': {'type': 'string'}, 'type': 'array'}, 'mandatory_checks': {'description': 'List of mandatory checks to enforce', 'items': {'type': 'string'}, 'type': 'array'}, 'override_spec': {'description': 'Path to spec file to override with', 'type': 'string'}, 'regions': {'description': 'Regions to test against', 'items': {'type': 'string'}, 'type': 'array'}, 'configure_rules': {'description': 'Configure rules', 'patternProperties': {'^.*$': {'type': 'object', 'patternProperties': {'^.*$': {'anyOf': [{'type': 'string'}, {'type': 'integer'}, {'type': 'boolean'}]}}}}, 'additionalProperties': False, 'type': 'object'}, 'templates': {'description': 'Templates to lint', 'items': {'type': 'string'}, 'type': 'array'}, 'ignore_templates': {'description': 'Templates to ignore', 'items': {'type': 'string'}, 'type': 'array'}}}
2020-03-31 14:24:27,802 - cfnlint - DEBUG - Config used: {}
2020-03-31 14:24:27,808 - cfnlint - DEBUG - CFNLINTRC looks valid!
2020-03-31 14:24:27,808 - cfnlint - DEBUG - Validating Project CFNLINTRC
2020-03-31 14:24:27,809 - cfnlint - DEBUG - Validating CFNLINTRC config with given JSONSchema
2020-03-31 14:24:27,809 - cfnlint - DEBUG - Schema used: {'$id': 'https://github.com/aws-cloudformation/cfn-python-lint/blob/master/src/cfnlint/data/CfnLintCli/config/schema.json', '$schema': 'http://json-schema.org/draft-07/schema#', 'description': 'CFNLINTRC configuration schema', 'title': 'CFNLINTRC JSON Schema', 'type': 'object', 'additionalProperties': False, 'properties': {'append_rules': {'description': 'Location of directories to append rules from', 'items': {'type': 'string'}, 'type': 'array'}, 'ignore_checks': {'description': 'List of checks to ignore', 'items': {'type': 'string'}, 'type': 'array'}, 'include_checks': {'description': 'List of checks to include', 'items': {'type': 'string'}, 'type': 'array'}, 'mandatory_checks': {'description': 'List of mandatory checks to enforce', 'items': {'type': 'string'}, 'type': 'array'}, 'override_spec': {'description': 'Path to spec file to override with', 'type': 'string'}, 'regions': {'description': 'Regions to test against', 'items': {'type': 'string'}, 'type': 'array'}, 'configure_rules': {'description': 'Configure rules', 'patternProperties': {'^.*$': {'type': 'object', 'patternProperties': {'^.*$': {'anyOf': [{'type': 'string'}, {'type': 'integer'}, {'type': 'boolean'}]}}}}, 'additionalProperties': False, 'type': 'object'}, 'templates': {'description': 'Templates to lint', 'items': {'type': 'string'}, 'type': 'array'}, 'ignore_templates': {'description': 'Templates to ignore', 'items': {'type': 'string'}, 'type': 'array'}}}
2020-03-31 14:24:27,811 - cfnlint - DEBUG - Config used: {}
2020-03-31 14:24:27,818 - cfnlint - DEBUG - CFNLINTRC looks valid!
2020-03-31 14:24:27,838 - cfnlint - DEBUG - User configuration loaded as
2020-03-31 14:24:27,840 - cfnlint - DEBUG - {}
2020-03-31 14:24:27,842 - cfnlint - DEBUG - Project configuration loaded as
2020-03-31 14:24:27,842 - cfnlint - DEBUG - {}
2020-03-31 14:24:27,843 - cfnlint - DEBUG - Merging configurations...
2020-03-31 14:24:27,844 - cfnlint - DEBUG - Begin linting of file: cloudlink-waf.template
2020-03-31 14:24:27,853 - cfnlint - DEBUG - Completed linting of file: cloudlink-waf.template
E0000 found unknown escape character '/'
cloudlink-waf.template:28:41
```

When I convert the template over to YAML it doesn't complain:
```
AppIdRegexPattern:
    Type: AWS::WAFv2::RegexPatternSet
    Properties:
      Name: x-mitel-app-regex
      Description: Handles validating an appropriate Mitel app identifier is present,
        and the app is provided
      Scope: REGIONAL
      RegularExpressionList:
      - "^app=[a-z-\\.0-9]+/[0-9.a-z-]+;"
```


Discussion:
what version of Python are you using?  Different versions of Python seem to have different error messages. 
Looks like I'm on `3.6.1`
I'm having trouble replicating this but I think I have an idea to fix it.  Looks like the err problem can come back as `found unknown escape character '/'` and we are looking for `found unknown escape character`.  Adding an or query to check with starts with.  I'll try to get that in shortly and we will see if it helps.

Resolving patch:
diff --git a/src/cfnlint/decode/__init__.py b/src/cfnlint/decode/__init__.py
--- a/src/cfnlint/decode/__init__.py
+++ b/src/cfnlint/decode/__init__.py
@@ -58,7 +58,8 @@ def decode(filename, ignore_bad_template):
     except ScannerError as err:
         if err.problem in [
                 'found character \'\\t\' that cannot start any token',
-                'found unknown escape character']:
+                'found unknown escape character'] or err.problem.startswith(
+                    'found unknown escape character'):
             try:
                 template = cfn_json.load(filename)
             except cfn_json.JSONDecodeError as json_err:


Test patch: