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

unsafeCss -> unsafeCSS for consistency with lit-html's unsafeHTML #524

Merged
merged 1 commit into from
Feb 4, 2019
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
<!-- ### Removed -->
<!-- ### Fixed -->
## Unreleased
### Changed
* [Breaking] Renamed `unsafeCss` to `unsafeCSS` for consistency with lit-html's `unsafeHTML`

## [2.0.0-rc.5] - 2019-01-24
### Fixed
Expand Down
2 changes: 1 addition & 1 deletion docs/api/assets/js/search.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/api/modules/_lib_css_tag_.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ <h3>css</h3>
<div class="lead">
<p>Template tag which which can be used with LitElement&#39;s <code>style</code> property to
set element styles. For security reasons, only literal string values may be
used. To incorporate non-literal values <code>unsafeCss</code> may be used inside a
used. To incorporate non-literal values <code>unsafeCSS</code> may be used inside a
template string part.</p>
</div>
</div>
Expand Down Expand Up @@ -351,4 +351,4 @@ <h2>Legend</h2>
ga('send', 'pageview');
</script>
</body>
</html>
</html>
10 changes: 5 additions & 5 deletions src/lib/css-tag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export class CSSResult {

constructor(cssText: string, safeToken: symbol) {
if (safeToken !== constructionToken) {
throw new Error('CSSResult is not constructable. Use `unsafeCss` or `css` instead.');
throw new Error('CSSResult is not constructable. Use `unsafeCSS` or `css` instead.');
}
this.cssText = cssText;
}
Expand Down Expand Up @@ -51,7 +51,7 @@ export class CSSResult {
* or exfiltrate data to an attacker controlled site. Take care to only use
* this with trusted input.
*/
export const unsafeCss = (value: unknown) => {
export const unsafeCSS = (value: unknown) => {
return new CSSResult(String(value), constructionToken);
};

Expand All @@ -61,15 +61,15 @@ const textFromCSSResult = (value: CSSResult) => {
} else {
throw new Error(
`Value passed to 'css' function must be a 'css' function result: ${
value}. Use 'unsafeCss' to pass non-literal values, but
value}. Use 'unsafeCSS' to pass non-literal values, but
take care to ensure page security.` );
}
};

/**
* Template tag which which can be used with LitElement's `style` property to
* set element styles. For security reasons, only literal string values may be
* used. To incorporate non-literal values `unsafeCss` may be used inside a
* used. To incorporate non-literal values `unsafeCSS` may be used inside a
* template string part.
*/
export const css =
Expand All @@ -78,4 +78,4 @@ export const css =
(acc, v, idx) => acc + textFromCSSResult(v) + strings[idx + 1],
strings[0]);
return new CSSResult(cssText, constructionToken);
};
};
8 changes: 4 additions & 4 deletions src/test/lit-element_styling_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import '@webcomponents/shadycss/apply-shim.min.js';

import {
css,
unsafeCss,
unsafeCSS,
CSSResult,
html as htmlWithStyles,
LitElement,
Expand Down Expand Up @@ -464,17 +464,17 @@ suite('Static get styles', () => {
});

test('`CSSResult` cannot be constructed', async () => {
// Note, this is done for security, instead use `css` or `unsafeCss`
// Note, this is done for security, instead use `css` or `unsafeCSS`
assert.throws(() => { new CSSResult('throw', Symbol()); });
});

test('Any value can be used in `css` when included with `unsafeCss`', async () => {
test('Any value can be used in `css` when included with `unsafeCSS`', async () => {
const name = generateElementName();
const someVar = `2px solid blue`;
customElements.define(name, class extends LitElement {
static get styles() {
return css`div {
border: ${unsafeCss(someVar)};
border: ${unsafeCSS(someVar)};
}`;
}

Expand Down