Skip to content

fix(parsing): handle edge case of blank strings as keys - #1

Merged
DoctorMcKay merged 1 commit into
DoctorMcKay:masterfrom
Cohedrin:master
Feb 8, 2017
Merged

fix(parsing): handle edge case of blank strings as keys#1
DoctorMcKay merged 1 commit into
DoctorMcKay:masterfrom
Cohedrin:master

Conversation

@Cohedrin

@Cohedrin Cohedrin commented Feb 8, 2017

Copy link
Copy Markdown
Contributor

Fixes edge case of blank strings being keys. Not sure why this would ever happen, but heres some test data.

meta.txt

Edit:

Output of this specific case before:

> BinaryKVParser.parse(fs.readFileSync('meta.txt'))
Error: Unknown KV type 49 encountered at offset 25

Expected output

{ '':
   { 'members:numMachines': '1',
     'members:numPlayers': '1',
     'members:numSlots': '10',
     uids: '����\u0001',
     'system:netflag': 'teamlobby',
     'system:network': 'LIVE',
     'system:access': 'public',
     'game:type': 'classic',
     'game:mode': 'competitive',
     'game:mapgroupname': 'mg_de_dust2,mg_de_train,mg_de_nuke,mg_de_mirage,mg_de_cache,mg_de_overpass,mg_de_cbble',
     'game:map': 'de_dust2',
     'game:prime': '1',
     'game:nby': '1',
     'game:state': 'lobby',
     'game:search_key': 'k13565',
     'game:ark': '0',
     'game:apr': '0',
     'game:loc': 'US',
     'options:anytypemode': '0',
     'options:server': 'official' } }

uids is still not parsed properly, but seems to be consistent with other parsers (i.e. https://github.com/ValvePython/vdf and https://github.com/SteamRE/SteamKit/blob/master/SteamKit2/SteamKit2/Types/KeyValue.cs#L850

@DoctorMcKay
DoctorMcKay merged commit dc552e6 into DoctorMcKay:master Feb 8, 2017
@DoctorMcKay

Copy link
Copy Markdown
Owner

Did you test this against typical input that previously parsed fine?

@Cohedrin

Copy link
Copy Markdown
Contributor Author

I did yes, I tested it against some test cases I found in other libs, for example here and the other binarykv's I'm using.

Test script for old data (from the above link):

const BinaryKVParser = require('binarykvparser');
var str = 'ADUAAmJpbGxpbmd0eXBlAAMAAAACY2hhbmdlbnVtYmVyAA9qGwACY29kZWNsYXNzAAEAAAACZ2FtZWNvZGUAAwAAAAJsaWNlbnNldHlwZQABAAAAAnBhY2thZ2VpZAAFAAAAAnN0YXR1cwAAAAAAAnRlcnJpdG9yeWNvZGUAAAAAAABleHRlbmRlZAACRGV2Q29tcAABAAAAAk9uUHVyY2hhc2VHcmFudEd1ZXN0UGFzc1BhY2thZ2UxACQBAAAIAGFwcGlkcwACMAAKAAAAAjEAFAAAAAIyAB4AAAACMwAoAAAAAjQAMgAAAAI1ADwAAAACNgBGAAAAAjcAggAAAAI4ANMAAAACOQDXAAAAAjEwANoAAAACMTEA3AAAAAIxMgDwAAAAAjEzAEABAAACMTQAVAEAAAIxNQDe4QMACABkZXBvdGlkcwACMAAAAAAAAjEA3QAAAAIyAPEAAAACMwAHAQAAAjQAVQEAAAI1AN/hAwAIAEFwcEl0ZW1zAAgICA==';
var buf = new Buffer(str, 'base64')'
BinaryKVParser.parse(buf);

Should output:

{ '5':
   { billingtype: 3,
     changenumber: 1796623,
     codeclass: 1,
     gamecode: 3,
     licensetype: 1,
     packageid: 5,
     status: 0,
     territorycode: 0,
     extended: { DevComp: 1, OnPurchaseGrantGuestPassPackage1: 292 },
     appids: [ 10, 20, 30, 40, 50, 60, 70, 130, 211, 215, 218, 220, 240, 320, 340, 254430 ],
     depotids: [ 0, 221, 241, 263, 341, 254431 ],
     AppItems: [] } }

@DoctorMcKay

Copy link
Copy Markdown
Owner

Perfect. I'll go ahead and publish this then.

@DoctorMcKay DoctorMcKay mentioned this pull request Feb 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants