Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update allowed tags/attributes from spec in amphtml 2004142326360 #4548

Merged
merged 7 commits into from
Apr 21, 2020
20 changes: 13 additions & 7 deletions bin/amphtml-update.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,10 @@ def GenValidatorProtoascii(validator_directory, out_dir):
"""
logging.info('entering ...')

protoascii_segments = [open(os.path.join(validator_directory, 'validator-main.protoascii')).read()]
protoascii_segments = [
open(os.path.join(validator_directory, 'validator-main.protoascii')).read(),
open(os.path.join(validator_directory, 'validator-css.protoascii')).read()
]
extensions = glob.glob(os.path.join(validator_directory, '../extensions/*/validator-*.protoascii'))
extensions.sort()
for extension in extensions:
Expand Down Expand Up @@ -445,10 +448,12 @@ def GetTagSpec(tag_spec, attr_lists):
if isinstance(field_value, (unicode, str, bool, int)):
cdata_dict[ field_descriptor.name ] = field_value
elif isinstance( field_value, google.protobuf.pyext._message.RepeatedCompositeContainer ):
cdata_dict[ field_descriptor.name ] = {}
cdata_dict[ field_descriptor.name ] = []
for value in field_value:
entry = {}
for (key,val) in value.ListFields():
cdata_dict[ field_descriptor.name ][ key.name ] = val
entry[ key.name ] = val
cdata_dict[ field_descriptor.name ].append( entry )
elif hasattr( field_value, '_values' ):
cdata_dict[ field_descriptor.name ] = {}
for _value in field_value._values:
Expand Down Expand Up @@ -482,10 +487,11 @@ def GetTagSpec(tag_spec, attr_lists):
cdata_dict['css_spec'] = css_spec
if len( cdata_dict ) > 0:
if 'blacklisted_cdata_regex' in cdata_dict:
if 'error_message' not in cdata_dict['blacklisted_cdata_regex']:
raise Exception( 'Missing error_message for blacklisted_cdata_regex.' );
if cdata_dict['blacklisted_cdata_regex']['error_message'] not in ( 'CSS !important', 'contents', 'html comments' ):
raise Exception( 'Unexpected error_message "%s" for blacklisted_cdata_regex.' % cdata_dict['blacklisted_cdata_regex']['error_message'] );
for entry in cdata_dict['blacklisted_cdata_regex']:
if 'error_message' not in entry:
raise Exception( 'Missing error_message for blacklisted_cdata_regex.' );
if entry['error_message'] not in ( 'contents', 'html comments', 'CSS i-amphtml- name prefix' ):
raise Exception( 'Unexpected error_message "%s" for blacklisted_cdata_regex.' % entry['error_message'] );
tag_spec_dict['cdata'] = cdata_dict

if 'spec_name' not in tag_spec_dict['tag_spec']:
Expand Down
Loading