Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Don’t index into strings with the theme() function
Indexing into a string is only ever going to produce a single character and is almost guaranteed to be a mistake. The legacy keypath notation is meant to traverse objects and arrays — not strings.
  • Loading branch information
thecrypticace committed Oct 13, 2025
commit a65dc80bc19c250c8e9837c802d4a46921ab066c
32 changes: 32 additions & 0 deletions packages/tailwindcss/src/compat/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1687,3 +1687,35 @@ test('handles setting theme keys to null', async () => {
"
`)
})

test('The theme() function does not try indexing into strings', async () => {
let compiler = await compile(css`
@theme default {
--color-what-50: #f00;
--color-what-950: #f00;
}

@theme {
/*
* The value of this theme variable is > 50 chars because colors.what.50 was previously
* indexing the string: "light-dark(theme(colors.what.950), theme(colors.what.50))"
* because the resolved config contained an object with a "what" key that was that string
*/
--color-what: light-dark(theme(colors.what.950), theme(colors.what.50));
}

@source inline("text-what");

@tailwind utilities;
`)

expect(compiler.build([])).toMatchInlineSnapshot(`
":root, :host {
--color-what: light-dark(#f00, #f00);
}
.text-what {
color: var(--color-what);
}
"
`)
})
5 changes: 5 additions & 0 deletions packages/tailwindcss/src/compat/plugin-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@ function get(obj: any, path: string[]) {
continue
}

// We never want to index into strings
if (typeof obj === 'string') {
return undefined
}

obj = obj[key]
}

Expand Down