Skip to content

Commit

Permalink
Revert "Change config to be an attribute getter."
Browse files Browse the repository at this point in the history
This reverts commit f3f52ce.

See discussion at WICG#107.
  • Loading branch information
otherdaniel committed Jul 9, 2021
1 parent fe767f0 commit 8679ece
Showing 1 changed file with 20 additions and 22 deletions.
42 changes: 20 additions & 22 deletions index.bs
Original file line number Diff line number Diff line change
Expand Up @@ -129,33 +129,33 @@ handle additional, application-specific use cases.
Exposed=(Window),
SecureContext
] interface Sanitizer {
constructor(optional SanitizerConfig aConfig = {});
constructor(optional SanitizerConfig config = {});

DocumentFragment sanitize(SanitizerInput input);
DOMString sanitizeToString(SanitizerInput input);

readonly attribute SanitizerConfig config;
static readonly attribute SanitizerConfig defaultConfig;
SanitizerConfig config();
static SanitizerConfig defaultConfig();
};
</pre>

* The <dfn constructor for=Sanitizer lt="Sanitizer()">
<code>new Sanitizer(<var>aConfig</var>)</code></dfn> constructor steps
are to create a new Sanitizer instance, and to retain a copy of |aConfig|
* The <dfn constructor for=Sanitizer lt="Sanitizer(config)">
<code>new Sanitizer(<var>config</var>)</code></dfn> constructor steps
are to create a new Sanitizer instance, and to retain a copy of |config|
as its [=configuration object=].
* The <dfn method for=Sanitizer><code>sanitize(<var>input</var>)</code></dfn>
method steps are to return the result of running the [=sanitize=]
algorithm on |input|,
* The <dfn method for=Sanitizer><code>sanitizeToString(<var>input</var>)</code></dfn>
method steps are to return the result of running [=sanitizeToString=]
algorithm on |input|.
* The <dfn attribute for=Sanitizer><code>config</code></dfn> attribute getter
steps steps are to return the result of running the [=query the sanitizer
config=] algorithm. It essentially returns a copy of the Sanitizer's
* The <dfn method for=Sanitizer><code>config()</code></dfn> method steps are
to return the result of running the [=query the sanitizer config=]
algorithm. It essentially returns a copy of the Sanitizer's
[=configuration object=], with some degree of normalization.
* The <dfn attribute for=Sanitizer><code>defaultConfig</code></dfn> attribute
getter steps are to return the value of the [=default configuration=]
object.
* The value of the static
<dfn method for=Sanitizer><code>defaultConfig()</code></dfn> method steps
are to return the value of the [=default configuration=] object.

Example:
```js
Expand Down Expand Up @@ -278,36 +278,34 @@ Examples:
```

A sanitizer's configuration can be queried using the
{{Sanitizer}}'s {{config}} read-only attribute. The default configuration
can be quried using the {{Sanitizer}}'s {{defaultConfig}} static read-only
attribute.
[=query the sanitizer config=] method.

Examples:
```js
// Does the default config allow script elements?
Sanitizer.defaultConfig.allowElements.includes("script") // false
Sanitizer.defaultConfig().allowElements.includes("script") // false

// We found a Sanitizer instance. Does it have an allow-list configured?
const a_sanitizer = ...;
!!a_sanitizer.config.allowElements // true, if an allowElements list is configured
!!a_sanitizer.config().allowElements // true, if an allowElements list is configured

// If it does have an allow elements list, does it include the <div> element?
a_sanitizer.config.allowElements.includes("div") // true, if "div" is in allowElements.
a_sanitizer.config().allowElements.includes("div") // true, if "div" is in allowElements.

// Note that the config attribute might do some normaliztion. E.g., it won't
// contain key/value pairs that are not declare in the IDL.
Object.keys(new Sanitizer({madeUpDictionaryKey: "Hello"}).config) // []
Object.keys(new Sanitizer({madeUpDictionaryKey: "Hello"}).config()) // []

// As a Sanitizer's config describes its operation, a new sanitizer with
// another instance's configuration should behave identically.
// (For illustration purposes only. It would make more sense to just use a directly.)
const a = /* ... a Sanitizer we found somewhere ... */;
const b = new Sanitizer(a.config); // b should behave the same as a.
const b = new Sanitizer(a.config()); // b should behave the same as a.

// defaultConfig and new Sanitizer().config should be the same.
// defaultConfig() and new Sanitizer().config should be the same.
// (For illustration purposes only. There are better ways of implementing
// object equality in JavaScript.)
JSON.stringify(Sanitizer.defaultConfig) == JSON.stringify(new Sanitizer().config); // true
JSON.stringify(Sanitizer.defaultConfig()) == JSON.stringify(new Sanitizer().config()); // true
```

### Attribute Match Lists ### {#attr-match-list}
Expand Down

0 comments on commit 8679ece

Please sign in to comment.