Skip to content

Commit

Permalink
fix(ui): env var with hyphen doesn't get highlighted (fixes #211)
Browse files Browse the repository at this point in the history
  • Loading branch information
flawiddsouza committed Aug 10, 2024
1 parent 7568b72 commit e633978
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 3 deletions.
38 changes: 36 additions & 2 deletions packages/ui/src/utils/codemirror-extensions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,40 @@ test('validate variableMatchingRegex', async() => {
},
{
var: '{{ cat! }}',
valid: false,
valid: true,
extract: [
'cat!'
]
},
{
// this one doesn't actually substitute in our env substitution, but it's a valid variable path actually
var: '{{ API["URL"] }}',
valid: true,
extract: [
'API["URL"]'
]
},
{
var: '{{ API[0].cat }}',
valid: true,
extract: [
'API[0].cat'
]
},
{
var: '{{API[0].cat!}}',
valid: true,
extract: [
'API[0].cat!'
]
},
{
// GH Issue #211
var: '{{my-key}}',
valid: true,
extract: [
'my-key'
]
},
]

Expand All @@ -74,7 +107,8 @@ test('validate variableMatchingRegex', async() => {
let i = 0
while ((match = variableMatchingRegex.exec(testValue.var))) {
const varName = match[1] || match[2]
expect(varName).toBe(testValue.extract![i])
const expectedVarName = testValue.extract ? testValue.extract[i] : 'extract array not defined for valid true case!'
expect(varName).toBe(expectedVarName)
i++
}

Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/utils/codemirror-extensions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ViewPlugin, Decoration, EditorView, ViewUpdate } from '@codemirror/view'
import { RangeSetBuilder } from '@codemirror/state'

export const variableMatchingRegex = /{{ ([.|\w]*?) }}|{{([.|\w]*?)}}/g
export const variableMatchingRegex = /{{ ([^\s]*?) }}|{{([^\s]*?)}}/g

export function envVarDecoration(envVariables: any) {
return ViewPlugin.fromClass(class {
Expand Down

0 comments on commit e633978

Please sign in to comment.