We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN 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-]+;"
```

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/cfnlint/decode/__init__.py`
Content:
```
1 """
2 Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.
3 SPDX-License-Identifier: MIT-0
4 """
5 import sys
6 import logging
7 import six
8 try:
9     from json.decoder import JSONDecodeError
10 except ImportError:
11     JSONDecodeError = ValueError
12 from yaml.parser import ParserError, ScannerError
13 from yaml import YAMLError
14 from cfnlint.decode import cfn_yaml, cfn_json
15 from cfnlint.rules import Match, ParseError
16 
17 
18 LOGGER = logging.getLogger(__name__)
19 
20 
21 def decode(filename, ignore_bad_template):
22     """
23         Decode filename into an object
24     """
25     template = None
26     matches = []
27     try:
28         template = cfn_yaml.load(filename)
29     except IOError as e:
30         if e.errno == 2:
31             LOGGER.error('Template file not found: %s', filename)
32             matches.append(create_match_file_error(
33                 filename, 'Template file not found: %s' % filename))
34         elif e.errno == 21:
35             LOGGER.error('Template references a directory, not a file: %s',
36                          filename)
37             matches.append(create_match_file_error(
38                 filename,
39                 'Template references a directory, not a file: %s' % filename))
40         elif e.errno == 13:
41             LOGGER.error('Permission denied when accessing template file: %s',
42                          filename)
43             matches.append(create_match_file_error(
44                 filename,
45                 'Permission denied when accessing template file: %s' % filename))
46 
47         if matches:
48             return(None, matches)
49     except UnicodeDecodeError as err:
50         LOGGER.error('Cannot read file contents: %s', filename)
51         matches.append(create_match_file_error(
52             filename, 'Cannot read file contents: %s' % filename))
53     except cfn_yaml.CfnParseError as err:
54         err.match.Filename = filename
55         matches = [err.match]
56     except ParserError as err:
57         matches = [create_match_yaml_parser_error(err, filename)]
58     except ScannerError as err:
59         if err.problem in [
60                 'found character \'\\t\' that cannot start any token',
61                 'found unknown escape character']:
62             try:
63                 template = cfn_json.load(filename)
64             except cfn_json.JSONDecodeError as json_err:
65                 json_err.match.filename = filename
66                 matches = [json_err.match]
67             except JSONDecodeError as json_err:
68                 if hasattr(json_err, 'message'):
69                     if json_err.message == 'No JSON object could be decoded':  # pylint: disable=no-member
70                         matches = [create_match_yaml_parser_error(err, filename)]
71                     else:
72                         matches = [create_match_json_parser_error(json_err, filename)]
73                 if hasattr(json_err, 'msg'):
74                     if json_err.msg == 'Expecting value':  # pylint: disable=no-member
75                         matches = [create_match_yaml_parser_error(err, filename)]
76                     else:
77                         matches = [create_match_json_parser_error(json_err, filename)]
78             except Exception as json_err:  # pylint: disable=W0703
79                 if ignore_bad_template:
80                     LOGGER.info('Template %s is malformed: %s',
81                                 filename, err.problem)
82                     LOGGER.info('Tried to parse %s as JSON but got error: %s',
83                                 filename, str(json_err))
84                 else:
85                     LOGGER.error(
86                         'Template %s is malformed: %s', filename, err.problem)
87                     LOGGER.error('Tried to parse %s as JSON but got error: %s',
88                                  filename, str(json_err))
89                     return (None, [create_match_file_error(
90                         filename,
91                         'Tried to parse %s as JSON but got error: %s' % (
92                             filename, str(json_err)))])
93         else:
94             matches = [create_match_yaml_parser_error(err, filename)]
95     except YAMLError as err:
96         matches = [create_match_file_error(filename, err)]
97 
98     if not isinstance(template, dict) and not matches:
99         # Template isn't a dict which means nearly nothing will work
100         matches = [Match(1, 1, 1, 1, filename, ParseError(),
101                          message='Template needs to be an object.')]
102     return (template, matches)
103 
104 
105 def create_match_yaml_parser_error(parser_error, filename):
106     """Create a Match for a parser error"""
107     lineno = parser_error.problem_mark.line + 1
108     colno = parser_error.problem_mark.column + 1
109     msg = parser_error.problem
110     return Match(
111         lineno, colno, lineno, colno + 1, filename,
112         ParseError(), message=msg)
113 
114 
115 def create_match_file_error(filename, msg):
116     """Create a Match for a parser error"""
117     return Match(
118         linenumber=1, columnnumber=1, linenumberend=1, columnnumberend=2,
119         filename=filename, rule=ParseError(), message=msg)
120 
121 
122 def create_match_json_parser_error(parser_error, filename):
123     """Create a Match for a parser error"""
124     if sys.version_info[0] == 3:
125         lineno = parser_error.lineno
126         colno = parser_error.colno
127         msg = parser_error.msg
128     elif sys.version_info[0] == 2:
129         lineno = 1
130         colno = 1
131         msg = parser_error.message
132     return Match(
133         lineno, colno, lineno, colno + 1, filename, ParseError(), message=msg)
134
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

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 @@
     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:

{"golden_diff": "diff --git a/src/cfnlint/decode/__init__.py b/src/cfnlint/decode/__init__.py\n--- a/src/cfnlint/decode/__init__.py\n+++ b/src/cfnlint/decode/__init__.py\n@@ -58,7 +58,8 @@\n     except ScannerError as err:\n         if err.problem in [\n                 'found character \\'\\\\t\\' that cannot start any token',\n-                'found unknown escape character']:\n+                'found unknown escape character'] or err.problem.startswith(\n+                    'found unknown escape character'):\n             try:\n                 template = cfn_json.load(filename)\n             except cfn_json.JSONDecodeError as json_err:\n", "issue": "E0000 found unknown escape character '/'\n*cfn-lint version: `0.29.2`*\r\n\r\n*Description of issue.*\r\n\r\nUsing a regex pattern in a JSON cfn template fails linting with `E000 found unknown escape character '/'`\r\n\r\nThis 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.\r\n\r\nThe JSON snippet that's causing issues is:\r\n```\r\n\"AppIdRegexPattern\": {\r\n            \"Type\": \"AWS::WAFv2::RegexPatternSet\",\r\n            \"Properties\": {\r\n                \"Name\": \"x-mitel-app-regex\",\r\n                \"Description\": \"Handles validating an appropriate Mitel app identifier is present, and the app is provided\",\r\n                \"Scope\": \"REGIONAL\",\r\n                \"RegularExpressionList\": [\r\n                    \"^app=[a-z-\\\\.0-9]+\\/[0-9.a-z-]+;\"\r\n                ]\r\n            }\r\n        }\r\n```\r\n\r\nHere's the debug output from linting the file\r\n\r\n```\r\n$ cfn-lint cloudlink-waf.template --debug\r\n2020-03-31 14:24:27,769 - cfnlint - DEBUG - Looking for CFLINTRC before attempting to load\r\n2020-03-31 14:24:27,770 - cfnlint - DEBUG - Validating User CFNLINTRC\r\n2020-03-31 14:24:27,771 - cfnlint - DEBUG - Validating CFNLINTRC config with given JSONSchema\r\n2020-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'}}}\r\n2020-03-31 14:24:27,802 - cfnlint - DEBUG - Config used: {}\r\n2020-03-31 14:24:27,808 - cfnlint - DEBUG - CFNLINTRC looks valid!\r\n2020-03-31 14:24:27,808 - cfnlint - DEBUG - Validating Project CFNLINTRC\r\n2020-03-31 14:24:27,809 - cfnlint - DEBUG - Validating CFNLINTRC config with given JSONSchema\r\n2020-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'}}}\r\n2020-03-31 14:24:27,811 - cfnlint - DEBUG - Config used: {}\r\n2020-03-31 14:24:27,818 - cfnlint - DEBUG - CFNLINTRC looks valid!\r\n2020-03-31 14:24:27,838 - cfnlint - DEBUG - User configuration loaded as\r\n2020-03-31 14:24:27,840 - cfnlint - DEBUG - {}\r\n2020-03-31 14:24:27,842 - cfnlint - DEBUG - Project configuration loaded as\r\n2020-03-31 14:24:27,842 - cfnlint - DEBUG - {}\r\n2020-03-31 14:24:27,843 - cfnlint - DEBUG - Merging configurations...\r\n2020-03-31 14:24:27,844 - cfnlint - DEBUG - Begin linting of file: cloudlink-waf.template\r\n2020-03-31 14:24:27,853 - cfnlint - DEBUG - Completed linting of file: cloudlink-waf.template\r\nE0000 found unknown escape character '/'\r\ncloudlink-waf.template:28:41\r\n```\r\n\r\nWhen I convert the template over to YAML it doesn't complain:\r\n```\r\nAppIdRegexPattern:\r\n    Type: AWS::WAFv2::RegexPatternSet\r\n    Properties:\r\n      Name: x-mitel-app-regex\r\n      Description: Handles validating an appropriate Mitel app identifier is present,\r\n        and the app is provided\r\n      Scope: REGIONAL\r\n      RegularExpressionList:\r\n      - \"^app=[a-z-\\\\.0-9]+/[0-9.a-z-]+;\"\r\n```\n", "before_files": [{"content": "\"\"\"\nCopyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.\nSPDX-License-Identifier: MIT-0\n\"\"\"\nimport sys\nimport logging\nimport six\ntry:\n    from json.decoder import JSONDecodeError\nexcept ImportError:\n    JSONDecodeError = ValueError\nfrom yaml.parser import ParserError, ScannerError\nfrom yaml import YAMLError\nfrom cfnlint.decode import cfn_yaml, cfn_json\nfrom cfnlint.rules import Match, ParseError\n\n\nLOGGER = logging.getLogger(__name__)\n\n\ndef decode(filename, ignore_bad_template):\n    \"\"\"\n        Decode filename into an object\n    \"\"\"\n    template = None\n    matches = []\n    try:\n        template = cfn_yaml.load(filename)\n    except IOError as e:\n        if e.errno == 2:\n            LOGGER.error('Template file not found: %s', filename)\n            matches.append(create_match_file_error(\n                filename, 'Template file not found: %s' % filename))\n        elif e.errno == 21:\n            LOGGER.error('Template references a directory, not a file: %s',\n                         filename)\n            matches.append(create_match_file_error(\n                filename,\n                'Template references a directory, not a file: %s' % filename))\n        elif e.errno == 13:\n            LOGGER.error('Permission denied when accessing template file: %s',\n                         filename)\n            matches.append(create_match_file_error(\n                filename,\n                'Permission denied when accessing template file: %s' % filename))\n\n        if matches:\n            return(None, matches)\n    except UnicodeDecodeError as err:\n        LOGGER.error('Cannot read file contents: %s', filename)\n        matches.append(create_match_file_error(\n            filename, 'Cannot read file contents: %s' % filename))\n    except cfn_yaml.CfnParseError as err:\n        err.match.Filename = filename\n        matches = [err.match]\n    except ParserError as err:\n        matches = [create_match_yaml_parser_error(err, filename)]\n    except ScannerError as err:\n        if err.problem in [\n                'found character \\'\\\\t\\' that cannot start any token',\n                'found unknown escape character']:\n            try:\n                template = cfn_json.load(filename)\n            except cfn_json.JSONDecodeError as json_err:\n                json_err.match.filename = filename\n                matches = [json_err.match]\n            except JSONDecodeError as json_err:\n                if hasattr(json_err, 'message'):\n                    if json_err.message == 'No JSON object could be decoded':  # pylint: disable=no-member\n                        matches = [create_match_yaml_parser_error(err, filename)]\n                    else:\n                        matches = [create_match_json_parser_error(json_err, filename)]\n                if hasattr(json_err, 'msg'):\n                    if json_err.msg == 'Expecting value':  # pylint: disable=no-member\n                        matches = [create_match_yaml_parser_error(err, filename)]\n                    else:\n                        matches = [create_match_json_parser_error(json_err, filename)]\n            except Exception as json_err:  # pylint: disable=W0703\n                if ignore_bad_template:\n                    LOGGER.info('Template %s is malformed: %s',\n                                filename, err.problem)\n                    LOGGER.info('Tried to parse %s as JSON but got error: %s',\n                                filename, str(json_err))\n                else:\n                    LOGGER.error(\n                        'Template %s is malformed: %s', filename, err.problem)\n                    LOGGER.error('Tried to parse %s as JSON but got error: %s',\n                                 filename, str(json_err))\n                    return (None, [create_match_file_error(\n                        filename,\n                        'Tried to parse %s as JSON but got error: %s' % (\n                            filename, str(json_err)))])\n        else:\n            matches = [create_match_yaml_parser_error(err, filename)]\n    except YAMLError as err:\n        matches = [create_match_file_error(filename, err)]\n\n    if not isinstance(template, dict) and not matches:\n        # Template isn't a dict which means nearly nothing will work\n        matches = [Match(1, 1, 1, 1, filename, ParseError(),\n                         message='Template needs to be an object.')]\n    return (template, matches)\n\n\ndef create_match_yaml_parser_error(parser_error, filename):\n    \"\"\"Create a Match for a parser error\"\"\"\n    lineno = parser_error.problem_mark.line + 1\n    colno = parser_error.problem_mark.column + 1\n    msg = parser_error.problem\n    return Match(\n        lineno, colno, lineno, colno + 1, filename,\n        ParseError(), message=msg)\n\n\ndef create_match_file_error(filename, msg):\n    \"\"\"Create a Match for a parser error\"\"\"\n    return Match(\n        linenumber=1, columnnumber=1, linenumberend=1, columnnumberend=2,\n        filename=filename, rule=ParseError(), message=msg)\n\n\ndef create_match_json_parser_error(parser_error, filename):\n    \"\"\"Create a Match for a parser error\"\"\"\n    if sys.version_info[0] == 3:\n        lineno = parser_error.lineno\n        colno = parser_error.colno\n        msg = parser_error.msg\n    elif sys.version_info[0] == 2:\n        lineno = 1\n        colno = 1\n        msg = parser_error.message\n    return Match(\n        lineno, colno, lineno, colno + 1, filename, ParseError(), message=msg)\n", "path": "src/cfnlint/decode/__init__.py"}], "after_files": [{"content": "\"\"\"\nCopyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved.\nSPDX-License-Identifier: MIT-0\n\"\"\"\nimport sys\nimport logging\nimport six\ntry:\n    from json.decoder import JSONDecodeError\nexcept ImportError:\n    JSONDecodeError = ValueError\nfrom yaml.parser import ParserError, ScannerError\nfrom yaml import YAMLError\nfrom cfnlint.decode import cfn_yaml, cfn_json\nfrom cfnlint.rules import Match, ParseError\n\n\nLOGGER = logging.getLogger(__name__)\n\n\ndef decode(filename, ignore_bad_template):\n    \"\"\"\n        Decode filename into an object\n    \"\"\"\n    template = None\n    matches = []\n    try:\n        template = cfn_yaml.load(filename)\n    except IOError as e:\n        if e.errno == 2:\n            LOGGER.error('Template file not found: %s', filename)\n            matches.append(create_match_file_error(\n                filename, 'Template file not found: %s' % filename))\n        elif e.errno == 21:\n            LOGGER.error('Template references a directory, not a file: %s',\n                         filename)\n            matches.append(create_match_file_error(\n                filename,\n                'Template references a directory, not a file: %s' % filename))\n        elif e.errno == 13:\n            LOGGER.error('Permission denied when accessing template file: %s',\n                         filename)\n            matches.append(create_match_file_error(\n                filename,\n                'Permission denied when accessing template file: %s' % filename))\n\n        if matches:\n            return(None, matches)\n    except UnicodeDecodeError as err:\n        LOGGER.error('Cannot read file contents: %s', filename)\n        matches.append(create_match_file_error(\n            filename, 'Cannot read file contents: %s' % filename))\n    except cfn_yaml.CfnParseError as err:\n        err.match.Filename = filename\n        matches = [err.match]\n    except ParserError as err:\n        matches = [create_match_yaml_parser_error(err, filename)]\n    except ScannerError as err:\n        if err.problem in [\n                'found character \\'\\\\t\\' that cannot start any token',\n                'found unknown escape character'] or err.problem.startswith(\n                    'found unknown escape character'):\n            try:\n                template = cfn_json.load(filename)\n            except cfn_json.JSONDecodeError as json_err:\n                json_err.match.filename = filename\n                matches = [json_err.match]\n            except JSONDecodeError as json_err:\n                if hasattr(json_err, 'message'):\n                    if json_err.message == 'No JSON object could be decoded':  # pylint: disable=no-member\n                        matches = [create_match_yaml_parser_error(err, filename)]\n                    else:\n                        matches = [create_match_json_parser_error(json_err, filename)]\n                if hasattr(json_err, 'msg'):\n                    if json_err.msg == 'Expecting value':  # pylint: disable=no-member\n                        matches = [create_match_yaml_parser_error(err, filename)]\n                    else:\n                        matches = [create_match_json_parser_error(json_err, filename)]\n            except Exception as json_err:  # pylint: disable=W0703\n                if ignore_bad_template:\n                    LOGGER.info('Template %s is malformed: %s',\n                                filename, err.problem)\n                    LOGGER.info('Tried to parse %s as JSON but got error: %s',\n                                filename, str(json_err))\n                else:\n                    LOGGER.error(\n                        'Template %s is malformed: %s', filename, err.problem)\n                    LOGGER.error('Tried to parse %s as JSON but got error: %s',\n                                 filename, str(json_err))\n                    return (None, [create_match_file_error(\n                        filename,\n                        'Tried to parse %s as JSON but got error: %s' % (\n                            filename, str(json_err)))])\n        else:\n            matches = [create_match_yaml_parser_error(err, filename)]\n    except YAMLError as err:\n        matches = [create_match_file_error(filename, err)]\n\n    if not isinstance(template, dict) and not matches:\n        # Template isn't a dict which means nearly nothing will work\n        matches = [Match(1, 1, 1, 1, filename, ParseError(),\n                         message='Template needs to be an object.')]\n    return (template, matches)\n\n\ndef create_match_yaml_parser_error(parser_error, filename):\n    \"\"\"Create a Match for a parser error\"\"\"\n    lineno = parser_error.problem_mark.line + 1\n    colno = parser_error.problem_mark.column + 1\n    msg = parser_error.problem\n    return Match(\n        lineno, colno, lineno, colno + 1, filename,\n        ParseError(), message=msg)\n\n\ndef create_match_file_error(filename, msg):\n    \"\"\"Create a Match for a parser error\"\"\"\n    return Match(\n        linenumber=1, columnnumber=1, linenumberend=1, columnnumberend=2,\n        filename=filename, rule=ParseError(), message=msg)\n\n\ndef create_match_json_parser_error(parser_error, filename):\n    \"\"\"Create a Match for a parser error\"\"\"\n    if sys.version_info[0] == 3:\n        lineno = parser_error.lineno\n        colno = parser_error.colno\n        msg = parser_error.msg\n    elif sys.version_info[0] == 2:\n        lineno = 1\n        colno = 1\n        msg = parser_error.message\n    return Match(\n        lineno, colno, lineno, colno + 1, filename, ParseError(), message=msg)\n", "path": "src/cfnlint/decode/__init__.py"}]}