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 with value/value_casei change #16858

Merged
merged 1 commit into from
Jul 18, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions contributing/component-validator-rules.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ tags: { # <amp-cat>
requires_extension: "amp-cat"
attrs: {
name: "data-selected-cat"
value_regex_casei: "(oscar|chloe|bella)"
value_casei: "bella"
value_casei: "chloe"
value_casei: "oscar"
}
attr_lists: "extended-amp-global"
amp_layout: {
Expand Down Expand Up @@ -228,13 +230,15 @@ matching extension script tag that we defined above.
```
attrs: {
name: "data-selected-cat"
value_regex_casei: "(oscar|chloe|bella)"
value_casei: "bella"
value_casei: "chloe"
value_casei: "oscar"
}
```

Here we specify the rules for validating the `data-selected-cat` attribute. In
our case, we tell the validator that we want the attribute value to
case-insensitively match the regular expression of "(oscar|chloe|bella)" which
case-insensitively match for either "bella", "chloe", or "oscar" which
essentially means the value must be one of those 3 options.

```
Expand Down Expand Up @@ -269,7 +273,9 @@ We saw a very simple example of an attribute validation rule above:
```
attrs: {
name: "data-selected-cat"
value_regex_casei: "(oscar|chloe|bella)"
value_casei: "bella"
value_casei: "chloe"
value_casei: "oscar"
}
```

Expand All @@ -286,12 +292,6 @@ By specifying no value rules, any value is allowed for this attribute.
If your code expects certain values, it is best to specify them here it will
produce helpful error messages for developers trying to debug their tag.

```
value_regex: "(oscar|chloe|bella)"
```

Similar to `value_regex_casei`, but case-sensitive.


```
value: "oscar"
Expand All @@ -302,13 +302,22 @@ value_casei: "oscar"
Specifies that only "oscar" is an allowed value, as case-sensitive and
case-insensitive variants.

```
value_regex: "\\d+"
```
```
value_regex_casei: "[a-z0-9]+"
```
Specifies that only values matching these RegEx patterns is an allowed value,
as case-sensitive and case-instensitive variants.


```
value_url: {
allow_empty: true
allow_relative: true
allowed_protocol: "https"
allowed_protocol: "http"
allow_relative: true
allow_empty: true
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you alphabetizing these? empty should come before relative.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No.

My preference that I've been enforcing because of OCD is that ordering for messages is based on order within validator.proto. Message values are alphabetized.

=D

}
```
This specifies that the attribute value must be a valid URL or an empty string.
Expand All @@ -324,7 +333,8 @@ Only one of:
- `value_regex_casei`
- `value_url`

may be specified for a single attribute.
may be specified for a single attribute. However, multiple values may be specified
for `value` and `value_casei` as seen in the example above.

Unless specified, attributes are all optional. To specify that an attribute is
mandatory, use the `mandatory` field:
Expand Down