mirror of
https://github.com/yannh/kubeconform.git
synced 2026-02-19 09:57:02 +00:00
Add Unicode Decoder
This commit is contained in:
parent
1bd44986dd
commit
704810be36
1 changed files with 8 additions and 0 deletions
|
|
@ -6,6 +6,8 @@ import json
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
import urllib.request
|
import urllib.request
|
||||||
|
import re
|
||||||
|
|
||||||
if 'DISABLE_SSL_CERT_VALIDATION' in os.environ:
|
if 'DISABLE_SSL_CERT_VALIDATION' in os.environ:
|
||||||
import ssl
|
import ssl
|
||||||
ssl._create_default_https_context = ssl._create_unverified_context
|
ssl._create_default_https_context = ssl._create_unverified_context
|
||||||
|
|
@ -93,6 +95,8 @@ def append_no_duplicates(obj, key, value):
|
||||||
if value not in obj[key]:
|
if value not in obj[key]:
|
||||||
obj[key].append(value)
|
obj[key].append(value)
|
||||||
|
|
||||||
|
def uescape_decode(match):
|
||||||
|
return match.group().encode().decode("unicode_escape")
|
||||||
|
|
||||||
def write_schema_file(schema, filename):
|
def write_schema_file(schema, filename):
|
||||||
schemaJSON = ""
|
schemaJSON = ""
|
||||||
|
|
@ -100,6 +104,10 @@ def write_schema_file(schema, filename):
|
||||||
schema = additional_properties(schema, skip=not os.getenv("DENY_ROOT_ADDITIONAL_PROPERTIES"))
|
schema = additional_properties(schema, skip=not os.getenv("DENY_ROOT_ADDITIONAL_PROPERTIES"))
|
||||||
schema = replace_int_or_string(schema)
|
schema = replace_int_or_string(schema)
|
||||||
schemaJSON = json.dumps(schema, indent=2)
|
schemaJSON = json.dumps(schema, indent=2)
|
||||||
|
# Replace \u with \\u using regex and decoding function
|
||||||
|
uescapes = re.compile(r"(?<!\\)\\u[0-9a-fA-F]{4}", re.UNICODE)
|
||||||
|
|
||||||
|
schemaJSON = uescapes.sub(uescape_decode, schemaJSON)
|
||||||
|
|
||||||
# Dealing with user input here..
|
# Dealing with user input here..
|
||||||
filename = os.path.basename(filename)
|
filename = os.path.basename(filename)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue