Skip to content

Clarify condition by splitting it up into explicitly named bools.#385

Open
otherdaniel wants to merge 4 commits intoWICG:mainfrom
otherdaniel:380-clarify
Open

Clarify condition by splitting it up into explicitly named bools.#385
otherdaniel wants to merge 4 commits intoWICG:mainfrom
otherdaniel:380-clarify

Conversation

@otherdaniel
Copy link
Copy Markdown
Collaborator

@otherdaniel otherdaniel commented Mar 23, 2026

Split the dreaded multi-line condition into several subclauses, assign each to an appropriately named boolean, and then test those bools.

That's more verbose than I usually go for, but it's surely more readable than the old version.

Fix: #380


Preview | Diff

@evilpie
Copy link
Copy Markdown
Collaborator

evilpie commented Mar 31, 2026

I have been thinking it might be cleaner to add a new algorithm like is attribute allowed. This might also be useful for #387, because we could use it like "is attribute allowed is".

@otherdaniel
Copy link
Copy Markdown
Collaborator Author

I have been thinking it might be cleaner to add a new algorithm like is attribute allowed. This might also be useful for #387, because we could use it like "is attribute allowed is".

Done. Please take another look.

Comment thread index.bs Outdated
1. [=/remove an attribute|Remove=] |attribute|.

1. If [=is attribute allowed=] for |attribute| given |configuration|
and |child| is `remove`,
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I would suggest using a boolean or a pair of singletons: https://infra.spec.whatwg.org/#singleton

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done. Using [=/blocked=] and [=/allowed=]

Comment thread index.bs Outdated
[=Attr/local name=] and [=Attr/namespace=].
1. Let |elementName| be a {{SanitizerElementNamespace}} with |current element|'s
[=Element/local name=] and [=Element/namespace=].
1. Let |elementWithLocalAttributes| be « [] ».
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
1. Let |elementWithLocalAttributes| be « [] ».
1. Let |elementWithLocalAttributes| be « ».

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

It was supposed to be an empty ordered map, per https://infra.spec.whatwg.org/#maps. Now I just use the phrase "empty ordered map", which is used elsewhere.

Comment thread index.bs Outdated
|configuration|["{{SanitizerConfig/elements}}"] [=SanitizerConfig/contains=]
|elementName|:
1. Set |elementWithLocalAttributes| to
|configuration|["{{SanitizerConfig/elements}}"][|elementName|].
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It was a list but now it's an object?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

:) It's now an empty ordered map or an IDL dictionary. I think I can use both with square brackets operator.

Comment thread index.bs Outdated
1. If |elementWithLocalAttributes|["{{SanitizerElementNamespaceWithAttributes/removeAttributes}}"] [=map/with default=] « »
[=SanitizerConfig/contains=] |attrName|:
1. Return `remove`.
1. Otherwise, if |configuration|["{{SanitizerConfig/attributes}}"] [=map/exists=]:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Do we need to say "Otherwise" here? We're using early returns after all.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Removed.

@evilpie
Copy link
Copy Markdown
Collaborator

evilpie commented Apr 7, 2026

Should we move the handleJavascriptNavigationUrls branch also into is attribute allowed?

@otherdaniel
Copy link
Copy Markdown
Collaborator Author

Should we move the handleJavascriptNavigationUrls branch also into is attribute allowed?

Done.

Comment thread index.bs
|elementName|:
1. Set |elementWithLocalAttributes| to the |item| in
|configuration|["{{SanitizerConfig/elements}}"] where
|elementName|[{{SanitizerElementNamespace/name}}] [=string/is=]
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this (and below) be |elementName|["{{SanitizerElementNamespace/name}}"] (with quotes)?

Comment thread index.bs
the [=built-in navigating URL attributes list=], and if |attribute|
[=contains a javascript: URL=], then return [=/blocked=].
1. If |current element|'s [=Element/namespace=] [=string/is=] the
[=MathML Namespace=] and |attr|'s [=Attr/local name=] [=string/is=]
Copy link
Copy Markdown
Collaborator

@evilpie evilpie Apr 10, 2026

Choose a reason for hiding this comment

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

Suggested change
[=MathML Namespace=] and |attr|'s [=Attr/local name=] [=string/is=]
[=MathML Namespace=] and |attribute|'s [=Attr/local name=] [=string/is=]

(and more)

@evilpie
Copy link
Copy Markdown
Collaborator

evilpie commented Apr 12, 2026

Sorry, I just realized that this won't really work for my idea of using this for implementing a manual is check, because in that case we don't have a real Attr attr attribute.

Comment thread index.bs
1. If |elementWithLocalAttributes|["{{SanitizerElementNamespaceWithAttributes/attributes}}"]
[=map/exists=] and |elementWithLocalAttributes|["{{SanitizerElementNamespaceWithAttributes/attributes}}"] does not [=SanitizerConfig/contain=] |attrName|:
1. Return [=/blocked=].
1. If |handleJavascriptNavigationUrls|:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sorry for flip-flopping on this, but please remove this again ... For #396.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Attribute allowing conditions seem wrong

3 participants