diff --git a/spec/System/TestCompareBuySimilar_spec.lua b/spec/System/TestCompareBuySimilar_spec.lua index 15f814310e..25abafaa9f 100644 --- a/spec/System/TestCompareBuySimilar_spec.lua +++ b/spec/System/TestCompareBuySimilar_spec.lua @@ -154,6 +154,13 @@ Implicits: 1 return dkjson.decode(queryJson) end + local function getUniqueQuery(name, baseName) + local item = new("Item", "Rarity: UNIQUE\n" .. name .. "\n" .. baseName .. "\nImplicits: 0") + local query = getQuery(openPopup(item, "Jewel")) + main:ClosePopup() + return query + end + it("rebuilds the URL when league and listed status change", function() local controls = openPopup() getQuery(controls) @@ -171,6 +178,25 @@ Implicits: 1 assert.equal("any", query.query.status.option) end) + it("preserves apostrophes in unique names", function() + local item = new("Item", [[ +Rarity: UNIQUE +Ralakesh's Impatience +Riveted Boots +Implicits: 0]]) + local controls = openPopup(item, "Boots") + + assert.equal("Ralakesh's Impatience", getQuery(controls).query.name) + end) + + it("removes a trailing unique ID without removing name punctuation", function() + assert.equal("Uul-Netol's Embrace", getUniqueQuery("Uul-Netol's Embrace 1234", "Vaal Axe").query.name) + end) + + it("trims whitespace after a unique name", function() + assert.equal("The Hateful Accuser", getUniqueQuery("The Hateful Accuser ", "Ghastly Eye Jewel").query.name) + end) + it("persists league choices by name for each realm", function() local controls = openPopup() assert.equal("PC Event", controls.leagueDrop:GetSelValue()) diff --git a/src/Classes/CompareBuySimilar.lua b/src/Classes/CompareBuySimilar.lua index ede83e401f..b1c48e585d 100644 --- a/src/Classes/CompareBuySimilar.lua +++ b/src/Classes/CompareBuySimilar.lua @@ -74,10 +74,10 @@ local function buildURL(item, slotName, controls, modEntries, defenceEntries, is -- Search by unique name -- Strip "Foulborn" prefix from unique name for trade search local tradeName = (item.title or item.name):gsub("^Foulborn%s+", "") - -- only take the first letters and white space to avoid e.g. including - -- timeless jewel ids or other numbers the user might have on the item - local nameMatch = tradeName:match("(%a[%a%s]+).*") - tradeName = (nameMatch and nameMatch:gsub("%s+$", "")) or tradeName + -- only strip a trailing numeric identifier to avoid e.g. including + -- timeless jewel ids or other numbers appended to the item name. + tradeName = tradeName:gsub("%s+$", "") + tradeName = tradeName:match("^(.-)%s+%d+$") or tradeName queryTable.query.name = tradeName queryTable.query.type = item.baseName -- If item is Foulborn, add the foulborn_item filter