Skip to content

Commit

Permalink
Fix escape hash clash (#1949)
Browse files Browse the repository at this point in the history
* Fix escape hash clash

* chore: add changeset

* chore: add tests
  • Loading branch information
anubra266 authored Jan 6, 2024
1 parent 439a0ef commit 657ca5d
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/gentle-jars-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@pandacss/shared': patch
---

Fix issue where `[]` escape hatch clashed with named grid lines
41 changes: 41 additions & 0 deletions packages/shared/__tests__/arbitrary-value.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import { describe, test, expect } from 'vitest'
import { getArbitraryValue } from '../src'

describe('arbitrary className', () => {
test('simple', () => {
expect(getArbitraryValue('[#3B00B9]')).toMatchInlineSnapshot('"#3B00B9"')
expect(getArbitraryValue('[123px]')).toMatchInlineSnapshot('"123px"')
})

test('named grid lines', () => {
expect(
getArbitraryValue(`
[full-start]
minmax(16px, 1fr)
[breakout-start]
minmax(0, 16px)
[content-start]
minmax(min-content, 1024px)
[content-end]
minmax(0, 16px)
[breakout-end]
minmax(16px, 1fr)
[full-end]
`),
).toMatchInlineSnapshot(`
"
[full-start]
minmax(16px, 1fr)
[breakout-start]
minmax(0, 16px)
[content-start]
minmax(min-content, 1024px)
[content-end]
minmax(0, 16px)
[breakout-end]
minmax(16px, 1fr)
[full-end]
"
`)
})
})
20 changes: 19 additions & 1 deletion packages/shared/src/arbitrary-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,25 @@ export const getArbitraryValue = (value: string) => {
if (!value) return value

if (value[0] === '[' && value[value.length - 1] === ']') {
return value.slice(1, -1)
const innerValue = value.slice(1, -1)
let bracketCount = 0

for (let i = 0; i < innerValue.length; i++) {
if (innerValue[i] === '[') {
bracketCount++
} else if (innerValue[i] === ']') {
if (bracketCount === 0) {
// Unmatched closing bracket found
return value
}
bracketCount--
}
}

if (bracketCount === 0) {
// All brackets are balanced
return innerValue
}
}

return value
Expand Down

1 comment on commit 657ca5d

@vercel
Copy link

@vercel vercel bot commented on 657ca5d Jan 6, 2024

Choose a reason for hiding this comment

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

Successfully deployed to the following URLs:

panda-docs – ./website

panda-docs-chakra-ui.vercel.app
panda-css.com
panda-docs-git-main-chakra-ui.vercel.app
panda-docs.vercel.app

Please sign in to comment.