diff --git a/__tests__/KeyValues3.save.txt b/__tests__/KeyValues3.save.txt index 5918eac..cdc4d9d 100644 --- a/__tests__/KeyValues3.save.txt +++ b/__tests__/KeyValues3.save.txt @@ -135,4 +135,8 @@ Second line of a multi-line string literal. r1 = deferred_resource:"" r2 = resource:"" } + "1" = + { + a = 1 + } } \ No newline at end of file diff --git a/__tests__/KeyValues3.test.ts b/__tests__/KeyValues3.test.ts index 571fae9..922052e 100644 --- a/__tests__/KeyValues3.test.ts +++ b/__tests__/KeyValues3.test.ts @@ -1,8 +1,8 @@ +import { describe, expect, test } from '@jest/globals'; +import crypto from 'crypto'; import { join } from 'path'; import { KV3BaseValue } from '../src/KeyValues3'; import { KeyValues3, getKeyValuesAdapter } from '../src/node'; -import { describe, expect, test } from '@jest/globals'; -import crypto from 'crypto'; describe('KeyValues3', () => { test('Check KeyValues3 Methods', () => { @@ -303,12 +303,19 @@ Second line of a multi-line string literal. } const obj = root.FindKey('objectValue')?.GetValue(); + expect(obj?.IsObject()).toBe(true); if (obj?.IsObject()) { expect(obj.FindKey('n')?.GetValue().Value()).toBe(5); expect(obj.FindKey('s')?.GetValue().Value()).toBe('foo'); expect(obj.FindKey('h')?.GetValue().IsArray()).toBe(true); } + const obj1 = root.FindKey('1')?.GetValue(); + expect(obj1?.IsObject()).toBe(true); + if (obj1?.IsObject()) { + expect(obj1.FindKey('a')?.GetValue().Value()).toBe(1); + } + expect( root .FindKey('objectValue') diff --git a/__tests__/KeyValues3.txt b/__tests__/KeyValues3.txt index 50eb10c..dc1db59 100644 --- a/__tests__/KeyValues3.txt +++ b/__tests__/KeyValues3.txt @@ -87,5 +87,9 @@ Second line of a multi-line string literal. m = .2-1 r1 = deferred_resource:"" r2 = resource:"" - } + }, + "1" = + { + a = 1 + } } \ No newline at end of file diff --git a/__tests__/__snapshots__/KeyValues3.test.ts.snap b/__tests__/__snapshots__/KeyValues3.test.ts.snap index 8c2c33e..68e0c70 100644 --- a/__tests__/__snapshots__/KeyValues3.test.ts.snap +++ b/__tests__/__snapshots__/KeyValues3.test.ts.snap @@ -197,5 +197,9 @@ Second line of a multi-line string literal. r1 = deferred_resource:"" r2 = resource:"" } + "1" = + { + a = 1 + } }" `; diff --git a/package.json b/package.json index 874622f..469bda5 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "easy-keyvalues", - "version": "1.2.4", + "version": "1.2.5", "description": "Parse Valve KeyValues Format and easy to use in nodejs or browser.", "main": "dist/node.js", "engines": { diff --git a/src/KeyValues3.ts b/src/KeyValues3.ts index 629e7a8..3c30d90 100644 --- a/src/KeyValues3.ts +++ b/src/KeyValues3.ts @@ -662,7 +662,8 @@ class ValueFeatureObject extends ValueObject { } } -const MatchKeyNoQuote = /^[\w\d_\.]+$/; +const MatchKeyNoQuote = /^[0-9a-zA-Z_\.]+$/; +const MatchKeyNumber = /^\d+$/; const MatchInt = /^-?\d+$/; const MatchDouble = /^-?\d+(\.\d+)?$/; const MatchDouble2 = /^-?\.\d+$/; @@ -850,7 +851,7 @@ export default class KeyValues3 { let prefix = ''; const root = this.IsRoot(); - if (MatchKeyNoQuote.test(this.Key)) { + if (MatchKeyNoQuote.test(this.Key) && !MatchKeyNumber.test(this.Key)) { prefix = `${tab}${this.Key} =`; } else { prefix = `${tab}"${this.Key}" =`;