fix(variables): remove quote stripping from short & long inputs (#1375)

* fix(variables): remove quote stripping from short & long inputs

* restore env

* remove quote stripping everywhere

* remove unused file
This commit is contained in:
Waleed
2025-09-18 11:04:22 -07:00
committed by GitHub
parent 6747a497fc
commit 5d96484501
9 changed files with 15 additions and 61 deletions

View File

@@ -432,7 +432,7 @@ export function ComboBox({
style={{ right: '42px' }}
>
<div className='w-full truncate text-foreground' style={{ scrollbarWidth: 'none' }}>
{formatDisplayText(displayValue, true)}
{formatDisplayText(displayValue)}
</div>
</div>
{/* Chevron button */}

View File

@@ -406,7 +406,7 @@ export function LongInput({
overflow: 'hidden',
}}
>
{formatDisplayText(value?.toString() ?? '', true)}
{formatDisplayText(value?.toString() ?? '')}
</div>
{/* Wand Button */}

View File

@@ -417,7 +417,7 @@ export function ShortInput({
>
{password && !isFocused
? '•'.repeat(value?.toString().length ?? 0)
: formatDisplayText(value?.toString() ?? '', true)}
: formatDisplayText(value?.toString() ?? '')}
</div>
</div>

View File

@@ -471,8 +471,7 @@ export function FieldFormat({
style={{ scrollbarWidth: 'none', minWidth: 'fit-content' }}
>
{formatDisplayText(
(localValues[field.id] ?? field.value ?? '')?.toString(),
true
(localValues[field.id] ?? field.value ?? '')?.toString()
)}
</div>
</div>

View File

@@ -337,7 +337,7 @@ export function McpServerModal({ open, onOpenChange, onServerCreated }: McpServe
className='whitespace-nowrap'
style={{ transform: `translateX(-${urlScrollLeft}px)` }}
>
{formatDisplayText(formData.url || '', true)}
{formatDisplayText(formData.url || '')}
</div>
</div>
</div>
@@ -389,7 +389,7 @@ export function McpServerModal({ open, onOpenChange, onServerCreated }: McpServe
transform: `translateX(-${headerScrollLeft[`key-${index}`] || 0}px)`,
}}
>
{formatDisplayText(key || '', true)}
{formatDisplayText(key || '')}
</div>
</div>
</div>
@@ -417,7 +417,7 @@ export function McpServerModal({ open, onOpenChange, onServerCreated }: McpServe
transform: `translateX(-${headerScrollLeft[`value-${index}`] || 0}px)`,
}}
>
{formatDisplayText(value || '', true)}
{formatDisplayText(value || '')}
</div>
</div>
</div>

View File

@@ -399,7 +399,7 @@ export function MCP() {
className='whitespace-nowrap'
style={{ transform: `translateX(-${urlScrollLeft}px)` }}
>
{formatDisplayText(formData.url || '', true)}
{formatDisplayText(formData.url || '')}
</div>
</div>
@@ -464,7 +464,7 @@ export function MCP() {
transform: `translateX(-${headerScrollLeft[`key-${index}`] || 0}px)`,
}}
>
{formatDisplayText(key || '', true)}
{formatDisplayText(key || '')}
</div>
</div>
</div>
@@ -500,7 +500,7 @@ export function MCP() {
transform: `translateX(-${headerScrollLeft[`value-${index}`] || 0}px)`,
}}
>
{formatDisplayText(value || '', true)}
{formatDisplayText(value || '')}
</div>
</div>
</div>
@@ -778,7 +778,7 @@ export function MCP() {
className='whitespace-nowrap'
style={{ transform: `translateX(-${urlScrollLeft}px)` }}
>
{formatDisplayText(formData.url || '', true)}
{formatDisplayText(formData.url || '')}
</div>
</div>
@@ -845,7 +845,7 @@ export function MCP() {
transform: `translateX(-${headerScrollLeft[`key-${index}`] || 0}px)`,
}}
>
{formatDisplayText(key || '', true)}
{formatDisplayText(key || '')}
</div>
</div>
</div>
@@ -881,7 +881,7 @@ export function MCP() {
transform: `translateX(-${headerScrollLeft[`value-${index}`] || 0}px)`,
}}
>
{formatDisplayText(value || '', true)}
{formatDisplayText(value || '')}
</div>
</div>
</div>

View File

@@ -1,33 +1,19 @@
'use client'
import type { ReactNode } from 'react'
import { VariableManager } from '@/lib/variables/variable-manager'
/**
* Formats text by highlighting block references (<...>) and environment variables ({{...}})
* Used in code editor, long inputs, and short inputs for consistent syntax highlighting
*
* @param text The text to format
* @param stripQuotes Whether to strip unnecessary quotes from the text (for plain text variables)
*/
export function formatDisplayText(text: string, stripQuotes = false): ReactNode[] {
export function formatDisplayText(text: string): ReactNode[] {
if (!text) return []
// If stripQuotes is true, remove surrounding quotes that might have been added
// This is needed when displaying plain type variables in inputs
let processedText = text
if (stripQuotes && typeof text === 'string') {
// Use VariableManager to determine if quotes should be stripped
if (VariableManager.shouldStripQuotesForDisplay(text)) {
processedText = text.slice(1, -1)
}
}
// Split the text by both tag patterns <something.something> and {{ENV_VAR}}
const parts = processedText.split(/(<[^>]+>|\{\{[^}]+\}\})/g)
const parts = text.split(/(<[^>]+>|\{\{[^}]+\}\})/g)
return parts.map((part, index) => {
// Handle block references
if (part.startsWith('<') && part.endsWith('>')) {
return (
<span key={index} className='text-blue-500'>
@@ -36,7 +22,6 @@ export function formatDisplayText(text: string, stripQuotes = false): ReactNode[
)
}
// Handle environment variables
if (part.match(/^\{\{[^}]+\}\}$/)) {
return (
<span key={index} className='text-blue-500'>

View File

@@ -215,21 +215,4 @@ describe('VariableManager', () => {
expect(VariableManager.formatForCodeContext(undefined, 'number')).toBe('undefined')
})
})
describe('shouldStripQuotesForDisplay', () => {
it.concurrent('should identify strings that need quotes stripped', () => {
expect(VariableManager.shouldStripQuotesForDisplay('"hello world"')).toBe(true)
expect(VariableManager.shouldStripQuotesForDisplay("'hello world'")).toBe(true)
expect(VariableManager.shouldStripQuotesForDisplay('hello world')).toBe(false)
expect(VariableManager.shouldStripQuotesForDisplay('""')).toBe(false) // Too short
expect(VariableManager.shouldStripQuotesForDisplay("''")).toBe(false) // Too short
})
it.concurrent('should handle edge cases', () => {
expect(VariableManager.shouldStripQuotesForDisplay('')).toBe(false)
expect(VariableManager.shouldStripQuotesForDisplay(null as any)).toBe(false)
expect(VariableManager.shouldStripQuotesForDisplay(undefined as any)).toBe(false)
expect(VariableManager.shouldStripQuotesForDisplay(42 as any)).toBe(false)
})
})
})

View File

@@ -225,7 +225,6 @@ export class VariableManager {
return typeof value === 'string' ? value : String(value)
}
if (type === 'string') {
// For backwards compatibility, add quotes only for string type in code context
return typeof value === 'string'
? JSON.stringify(value)
: VariableManager.formatValue(value, type, 'code')
@@ -233,16 +232,4 @@ export class VariableManager {
return VariableManager.formatValue(value, type, 'code')
}
/**
* Determines whether quotes should be stripped for display.
*/
static shouldStripQuotesForDisplay(value: string): boolean {
if (!value || typeof value !== 'string') return false
return (
(value.startsWith('"') && value.endsWith('"') && value.length > 2) ||
(value.startsWith("'") && value.endsWith("'") && value.length > 2)
)
}
}