diff --git a/CHANGELOG.md b/CHANGELOG.md index da49e418..eb488258 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [1.40.2] + +- Fix var_export so that keys are properly quoted. + ## [1.40.0] - Add Listen for Xdebug to debug panel. diff --git a/src/test/adapter.ts b/src/test/adapter.ts index 7d0decfe..1b506aac 100644 --- a/src/test/adapter.ts +++ b/src/test/adapter.ts @@ -849,7 +849,7 @@ describe('PHP Debug Adapter', () => { { context: 'clipboard', expression: '$anArray', - result: 'array (\n 0 => 1,\n test => 2,\n test2 => \n array (\n t => 123,\n ),\n)', + result: "array (\n 0 => 1,\n 'test' => 2,\n 'test2' => \n array (\n 't' => 123,\n ),\n)", hasVariablesReference: false, }, { context: 'clipboard', expression: '$aBoolean', result: 'true', hasVariablesReference: false }, diff --git a/src/varExport.ts b/src/varExport.ts index 2632ce2b..421037b7 100644 --- a/src/varExport.ts +++ b/src/varExport.ts @@ -22,14 +22,12 @@ export async function varExportProperty(property: xdebug.Property, indent: strin displayValue = ( await Promise.all( properties.map(async property => { + const name = /^-?[0-9]+$/.test(property.name) ? `${property.name}` : `'${property.name}'` const indent2 = indent + ' ' if (property.hasChildren) { - return `${indent2}${property.name} => \n${indent2}${await varExportProperty( - property, - indent2 - )},` + return `${indent2}${name} => \n${indent2}${await varExportProperty(property, indent2)},` } else { - return `${indent2}${property.name} => ${await varExportProperty(property, indent2)},` + return `${indent2}${name} => ${await varExportProperty(property, indent2)},` } }) )