HearthSim / Hearthstone-Deck-Tracker

A deck tracker and deck manager for Hearthstone on Windows
https://hsreplay.net/downloads/
4.61k stars 1.11k forks source link

StringImporter not importing cards with ranks #4272

Closed Urkaz closed 3 years ago

Urkaz commented 3 years ago

Bug report

Expected Behavior

All cards should be imported correctly.

Actual Behavior

The StringImporter is not importing cards that contain parenthesis in the name (for example cards with "(Rank 1)").

Steps to reproduce behavior

  1. Open HDT.
  2. Copy the following text:

    Shadowstep x 2 Brain Freeze x 2 Guardian Augmerchant x 2 Pen Flinger x 2 Prize Plunderer x 2 Secret Passage x 2 Wand Thief x 2 Efficient Octo-bot x 2 Far Watch Post x 2 Swindle x 2 Wicked Stab (Rank 1) x 2 Field Contact x 2 Mankrik Mor'shan Watch Post x 2 Kazakus, Golem Shaper Jandice Barov Kargal Battlescar

  3. Select Import > Other > Clipboard > Save Only
  4. Notice that the card "Wicked Stab (Rank 1)" is not imported.

Log/Screenshots

Warning|Database.GetCardFromName >> Could not get card from name: x

image

Fix

After checking the source code, I managed to fix this by just adding the parenthesis to the regex used in StringImported.cs:

private static readonly Regex CardLineRegexCountFirst = new Regex(@"(^(\s*)(?<count>\d)(\s*x)?\s+)(?<cardname>[\w\s'\.:!\-(),]+)");
private static readonly Regex CardLineRegexCountLast = new Regex(@"(?<cardname>[\w\s'\.:!\-(),]+?)(\s+(x\s*)?(?<count>\d))(\s*)$");