kionell / osu-parsers

A bundle of decoders/encoders for osu! file formats based on the osu!lazer source code.
MIT License
36 stars 8 forks source link

Empty first line in a map throws "Not a valid beatmap!" error #15

Closed Soiiyu closed 10 months ago

Soiiyu commented 11 months ago

If there is an empty line above the osu file format v line, the parser throws Error: Failed to decode a beatmap: Not a valid beatmap!.

This only really appeared in 1 map out of the ~2,500 I've parsed (https://osu.ppy.sh/b/1485848), so it's not a very big problem as far as I know.

image

A quick fix I tried adding was:

this._reset();
this._lines = this._getLines(data);
this._setEnabledSections(typeof options !== 'boolean' ? options : {});
this._sbLines = this._shouldParseStoryboard(options) ? [] : null;

// Remove first line if it's empty
if (this._lines[0] == '') this._lines.shift()

const fileFormatLine = this._lines[0].trim();

if (!fileFormatLine.startsWith('osu file format v')) {
  throw new Error('Not a valid beatmap!');
}

inside the decodeFromLines() function at node.cjs:2700 and node.mjs:2696. or at BeatmapDecoder.ts:121.

kionell commented 11 months ago

Oh, that's a good catch. I never really thought this could be found in a submitted beatmap.

Soiiyu commented 11 months ago

Hopefully it's one of those rare cases, like Skystar's Asymmetry map having that "\uFEFF" symbol. The editor seems to do it's best trimming all the extra whitespace, so I can't imagine newer maps having it.

Regardless, this is a great parser, thank you for your work!