Skip to content

Commit 5cee262

Browse files
authored
fix: When generating var_export clipboard, quote non numeric keys (#1150)
* When generating var_export clipboard, quote non numeric keys * Update CHANGELOG.md
1 parent 983884e commit 5cee262

3 files changed

Lines changed: 8 additions & 6 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [1.40.2]
8+
9+
- Fix var_export so that keys are properly quoted.
10+
711
## [1.40.0]
812

913
- Add Listen for Xdebug to debug panel.

‎src/test/adapter.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ describe('PHP Debug Adapter', () => {
849849
{
850850
context: 'clipboard',
851851
expression: '$anArray',
852-
result: 'array (\n 0 => 1,\n test => 2,\n test2 => \n array (\n t => 123,\n ),\n)',
852+
result: "array (\n 0 => 1,\n 'test' => 2,\n 'test2' => \n array (\n 't' => 123,\n ),\n)",
853853
hasVariablesReference: false,
854854
},
855855
{ context: 'clipboard', expression: '$aBoolean', result: 'true', hasVariablesReference: false },

‎src/varExport.ts‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,12 @@ export async function varExportProperty(property: xdebug.Property, indent: strin
2222
displayValue = (
2323
await Promise.all(
2424
properties.map(async property => {
25+
const name = /^-?[0-9]+$/.test(property.name) ? `${property.name}` : `'${property.name}'`
2526
const indent2 = indent + ' '
2627
if (property.hasChildren) {
27-
return `${indent2}${property.name} => \n${indent2}${await varExportProperty(
28-
property,
29-
indent2
30-
)},`
28+
return `${indent2}${name} => \n${indent2}${await varExportProperty(property, indent2)},`
3129
} else {
32-
return `${indent2}${property.name} => ${await varExportProperty(property, indent2)},`
30+
return `${indent2}${name} => ${await varExportProperty(property, indent2)},`
3331
}
3432
})
3533
)

0 commit comments

Comments
 (0)