Skip to content
New issue

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

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

Already on GitHub? # to your account

Prevent breaking maps with list-like CSS values #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

chriskirknielsen
Copy link

Problem

A JSON value for a font-family value can contain commas that currently, when output in Sass, break the map, e.g.:

{
    "fonts": {
        "serif": "Georgia, 'Times New Roman', serif",
        "sans": "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif",
    }
}

…outputs…

$data: (
    fonts: (
        serif: Georgia, 'Times New Roman', serif,
        sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif,
        mono: Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace
    )
)

Proposed solution

This proposed change wraps list-like strings in parentheses so that the contents don't break the map:

$data: (
    fonts: (
        serif: (Georgia, 'Times New Roman', serif),
        sans: (-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif),
        mono: (Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace)
    )
)

And Sass will convert the list to a normal CSS-valid list without parentheses when used, like so:

$fonts: map-get($data, 'fonts');
$fonts-sans: map-get($fonts, 'sans');
body { font-family: $fonts-sans; }

…becomes…

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; }

Note

A value like rgb(255,255,255) contains commas, so technically this fix would also wrap any CSS function with multiple arguments in parentheses, but Sass is forgiving enough that this will output safely.

# Problem
A JSON value for a `font-family` value can contain commas that currently, when output in Sass, break the map, e.g.:

```json
{
    "fonts": {
        "serif": "Georgia, 'Times New Roman', serif",
        "sans": "-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif",
    }
}
```

…outputs…

```scss
$data: (
    fonts: (
        serif: Georgia, 'Times New Roman', serif,
        sans: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif,
        mono: Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace
    )
)
```

# Proposed solution
This proposed change wraps list-like strings in parentheses so that the contents don't break the map:

```scss
$data: (
    fonts: (
        serif: (Georgia, 'Times New Roman', serif),
        sans: (-apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif),
        mono: (Menlo, Monaco, Consolas, 'Liberation Mono', 'Courier New', monospace)
    )
)
```

And Sass will convert the list to a normal CSS-valid list without parentheses when used, like so:

```scss
$fonts: map-get($data, 'fonts');
$fonts-sans: map-get($fonts, 'sans');
body { font-family: $fonts-sans; }
```
…becomes…
```css
body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif; }
```

# Note
A value like `rgb(255,255,255)` contains commas, so technically this fix would also wrap any CSS function with multiple arguments in parentheses, but Sass is forgiving enough that this will output safely.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant