Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: NPE on invalid locations #1217

Merged
merged 1 commit into from Oct 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -158,6 +158,7 @@ public void locations() {

for (var id : locs) {
var adv = AdventureDatabase.getAdventure(id);
if (adv == null) continue;
var env = locMapping.computeIfAbsent(adv.getEnvironment(), m -> new HashMap<>());
env.computeIfAbsent(adv.getDifficultyLevel(), m -> new ArrayList<>()).add(adv);
}
Expand Down
Expand Up @@ -301,6 +301,22 @@ public void upgradesIfUpgrades(String filePart, String upgrades) {

@Nested
class Locations {
@Test
public void doesNotCrashWithAbsentLocations() {
var cleanups =
new Cleanups(
hasAutumnaton(),
withItem(ItemPool.AUTUMNATON),
withProperty("autumnatonUpgrades", ""),
withNextResponse(200, html("request/test_choice_autumnaton_old_locations.html")));

try (cleanups) {
String output = execute("locations");
assertContinueState();
assertThat(output, containsString("<li>The Haunted Wine Cellar</li>"));
}
}

@Test
public void showsLocations() {
var cleanups =
Expand Down
253 changes: 253 additions & 0 deletions test/root/request/test_choice_autumnaton_old_locations.html
@@ -0,0 +1,253 @@
<html><head>
<script language=Javascript>
<!--
if (parent.frames.length == 0) location.href="game.php";
//-->
</script>
<script language=Javascript src="https://d2uyhvukfffg5a.cloudfront.net/scripts/jquery-1.5.1.js"></script>
<script language=Javascript src="https://d2uyhvukfffg5a.cloudfront.net/scripts/keybinds.min.2.js"></script>
<script language=Javascript src="https://d2uyhvukfffg5a.cloudfront.net/scripts/window.20111231.js"></script>
<script language="javascript">function chatFocus(){if(top.chatpane.document.chatform.graf) top.chatpane.document.chatform.graf.focus();}
if (typeof defaultBind != 'undefined') { defaultBind(47, 2, chatFocus); defaultBind(190, 2, chatFocus);defaultBind(191, 2, chatFocus); defaultBind(47, 8, chatFocus);defaultBind(190, 8, chatFocus); defaultBind(191, 8, chatFocus); }</script><script>
function switchFocus()
{
if (top.chatpane.document.chatform.graf.focus)
top.chatpane.document.chatform.graf.focus();
return false;
}
function repeat()
{
var linx = document.getElementsByTagName("A");
for (var i = 0; i < linx.length; i++)
{
if (typeof timersfunc != 'undefined') {
if (!timersfunc()) {
return;
}
timersfunc = null;
}
var link = linx[i];
if (link.innerHTML.match(/Adventure Again/) || link.innerHTML.match(/Do it again/))
location.href = link.href;
}
}

defaultBind(47, CTRL, switchFocus);
defaultBind(191, CTRL, switchFocus);
defaultBind(47, META, switchFocus);
defaultBind(191, META, switchFocus);
defaultBind(192, NONE, repeat);
defaultBind(220, NONE, repeat);
</script><script language="javascript">
function updateParseItem(iid, field, info) {
var tbl = $('#ic'+iid);
var data = parseItem(tbl);
if (!data) return;
data[field] = info;
var out = [];
for (i in data) {
if (!data.hasOwnProperty(i)) continue;
out.push(i+'='+data[i]);
}
tbl.attr('rel', out.join('&'));
}
function parseItem(tbl) {
tbl = $(tbl);
var rel = tbl.attr('rel');
var data = {};
if (!rel) return data;
var parts = rel.split('&');
for (i in parts) {
if (!parts.hasOwnProperty(i)) continue;
var kv = parts[i].split('=');
tbl.data(kv[0], kv[1]);
data[kv[0]] = kv[1];
}
return data;
}
</script><script type="text/javascript" src="https://d2uyhvukfffg5a.cloudfront.net/scripts/pop_query.20130705.js"></script>
<script type="text/javascript"> function pop_ircm(clicked) { return false; } </script><script>

var currentkey = 49;
$(document).ready(function () {
$('form').each(function () {
var form = this;
defaultBind(currentkey++, NONE, function () { form.submit(); });
return currentkey < 58;
});
});

</script> <link rel="stylesheet" type="text/css" href="https://d2uyhvukfffg5a.cloudfront.net/styles.20151006.css">
<style type='text/css'>
.faded {
zoom: 1;
filter: alpha(opacity=35);
opacity: 0.35;
-khtml-opacity: 0.35;
-moz-opacity: 0.35;
}
</style>

</head>

<body>
<Center><table width=95% cellspacing=0 cellpadding=0><tr><td style="color: white;" align=center bgcolor=blue><b>Direct Autumn-Aton</b></td></tr><tr><td style="padding: 5px; border: 1px solid blue;"><center><table><tr><td><center>
<div style="position: relative; height: 150px; width: 150px;">
<img src="https://d2uyhvukfffg5a.cloudfront.net/otherimages/autumnaton/base.png" height="150" width="150" style="position: absolute; left: 0px; top: 0px;" />
<img src="https://d2uyhvukfffg5a.cloudfront.net/otherimages/autumnaton/leftarm0.png" style="position: absolute; left: 0px; top: 0px;" />
<img src="https://d2uyhvukfffg5a.cloudfront.net/otherimages/autumnaton/leftleg0.png" style="position: absolute; left: 0px; top: 0px;" />
<img src="https://d2uyhvukfffg5a.cloudfront.net/otherimages/autumnaton/rightarm0.png" style="position: absolute; left: 0px; top: 0px;" />
<img src="https://d2uyhvukfffg5a.cloudfront.net/otherimages/autumnaton/rightleg0.png" style="position: absolute; left: 0px; top: 0px;" />
</div>
<div style="border: 1px solid black; font-family: monospace; padding: 1em">
Estimated Expedition Time: 11 adventures<br />
Visual Acuity: Adequate<br />
Zone Collection Estimate: 3<br />
Seasonal Collection Estimate: 1<br />
Expected Experiential Transfer: 66<br />
</div>

<p>

<form method="post" action="choice.php">
<input type="hidden" name="option" value="2" />
<input type="hidden" name="pwd" value="923738632155532b6a3b80050d0b0298" />
<input type="hidden" name="whichchoice" value="1483" />
<input type="submit" class="button" value="Send your autumn-aton to: " />
<select required name="heythereprogrammer">
<option selected disabled value="">-- select a location --</option>
<option value="233">A Barroom Brawl</option>
<option value="350">A Massive Ziggurat</option>
<option value="384">A Mob of Zeppelin Protesters</option>
<option value="296">A-Boo Peak</option>
<option value="348">An Overgrown Shrine (Northeast)</option>
<option value="346">An Overgrown Shrine (Northwest)</option>
<option value="349">An Overgrown Shrine (Southeast)</option>
<option value="347">An Overgrown Shrine (Southwest)</option>
<option value="257">Cobb's Knob Barracks</option>
<option value="259">Cobb's Knob Harem</option>
<option value="258">Cobb's Knob Kitchens</option>
<option value="50">Cobb's Knob Laboratory</option>
<option value="51">Cobb's Knob Menagerie, Level 1</option>
<option value="52">Cobb's Knob Menagerie, Level 2</option>
<option value="53">Cobb's Knob Menagerie, Level 3</option>
<option value="260">Cobb's Knob Treasury</option>
<option value="18">Degrassi Knoll</option>
<option value="13">Gausie's Grotto</option>
<option value="31">Guano Junction</option>
<option value="243">Infernal Rackets Backstage</option>
<option value="270">Itznotyerzitz Mine</option>
<option value="272">Lair of the Ninja Snowmen</option>
<option value="440">Madness Bakery</option>
<option value="155">McMillicancuddy's Farm</option>
<option value="236">Neckback Crick</option>
<option value="213">Nemesis Cave</option>
<option value="240">Noob Cave</option>
<option value="298">Oil Peak</option>
<option value="125">OLD The Middle Chamber</option>
<option value="124">OLD The Upper Chamber</option>
<option value="248">Pandamonium Slums</option>
<option value="228">Professor Jacking's Huge-A-Ma-Tron</option>
<option value="227">Professor Jacking's Small-O-Fier</option>
<option value="136">Sonofa Beach</option>
<option value="45">South of the Border</option>
<option value="20">The "Fun" House</option>
<option value="121">The Arid, Extra-Dry Desert</option>
<option value="123">The Arid, Extra-Dry Desert</option>
<option value="364">The Arid, Extra-Dry Desert</option>
<option value="30">The Bat Hole Entrance</option>
<option value="32">The Batrat and Ratbat Burrow</option>
<option value="33">The Beanbat Chamber</option>
<option value="405">The Black Forest</option>
<option value="111">The Black Forest (OLD)</option>
<option value="322">The Castle in the Clouds in the Sky (Basement)</option>
<option value="323">The Castle in the Clouds in the Sky (Ground Floor)</option>
<option value="324">The Castle in the Clouds in the Sky (Top Floor)</option>
<option value="383">The Copperhead Club</option>
<option value="419">The Crimbonium Mining Camp</option>
<option value="325">The Daily Dungeon</option>
<option value="417">The Deep Dark Jungle</option>
<option value="352">The Degrassi Knoll Bakery</option>
<option value="354">The Degrassi Knoll Garage</option>
<option value="353">The Degrassi Knoll Gym</option>
<option value="351">The Degrassi Knoll Restroom</option>
<option value="92">The Dire Warren</option>
<option value="39">The Dungeons of Doom</option>
<option value="232">The Electric Lemonade Acid Parade</option>
<option value="273">The eXtreme Slope</option>
<option value="452">The Fungal Nethers</option>
<option value="271">The Goatlet</option>
<option value="138">The Haiku Dungeon</option>
<option value="395">The Haunted Ballroom</option>
<option value="392">The Haunted Bathroom</option>
<option value="107">The Haunted Bathroom (OLD)</option>
<option value="393">The Haunted Bedroom</option>
<option value="108">The Haunted Bedroom (OLD)</option>
<option value="391">The Haunted Billiards Room</option>
<option value="105">The Haunted Billiards Room (OLD)</option>
<option value="399">The Haunted Boiler Room</option>
<option value="389">The Haunted Conservatory</option>
<option value="103">The Haunted Conservatory (OLD)</option>
<option value="394">The Haunted Gallery</option>
<option value="388">The Haunted Kitchen</option>
<option value="102">The Haunted Kitchen (OLD)</option>
<option value="396">The Haunted Laboratory</option>
<option value="400">The Haunted Laundry Room</option>
<option value="390">The Haunted Library</option>
<option value="397">The Haunted Nursery</option>
<option value="113">The Haunted Pantry</option>
<option value="398">The Haunted Storage Room</option>
<option value="401">The Haunted Wine Cellar</option>
<option value="179">The Haunted Wine Cellar (Northeast)</option>
<option value="178">The Haunted Wine Cellar (Northwest)</option>
<option value="181">The Haunted Wine Cellar (Southeast)</option>
<option value="180">The Haunted Wine Cellar (Southwest)</option>
<option value="341">The Hidden Apartment Building</option>
<option value="344">The Hidden Bowling Alley</option>
<option value="118">The Hidden City</option>
<option value="342">The Hidden Hospital</option>
<option value="343">The Hidden Office Building</option>
<option value="345">The Hidden Park</option>
<option value="280">The Hidden Temple</option>
<option value="26">The Hippy Camp</option>
<option value="83">The Hole in the Sky</option>
<option value="154">The Junkyard</option>
<option value="101">The Knob Shaft</option>
<option value="242">The Laugh Floor</option>
<option value="19">The Limerick Dungeon</option>
<option value="415">The Mansion of Dr. Weirdeaux</option>
<option value="407">The Middle Chamber</option>
<option value="122">The Oasis</option>
<option value="66">The Obligatory Pirate's Cove</option>
<option value="356">The Old Landfill</option>
<option value="150">The Orcish Frat House (Bombed Back to the Stone Age)</option>
<option value="114">The Outskirts of Cobb's Knob</option>
<option value="441">The Overgrown Lot</option>
<option value="119">The Palindome (OLD)</option>
<option value="81">The Penultimate Fantasy Airship</option>
<option value="71">The Poker Room</option>
<option value="385">The Red Zeppelin</option>
<option value="439">The Skeleton Store</option>
<option value="112">The Sleazy Back Alley</option>
<option value="295">The Smut Orc Logging Camp</option>
<option value="363">The Space Odyssey Discotheque</option>
<option value="15">The Spooky Forest</option>
<option value="387">The Thinknerd Warehouse</option>
<option value="21">The Unquiet Garves</option>
<option value="406">The Upper Chamber</option>
<option value="80">The Valley of Rof L'm Fao</option>
<option value="58">The VERY Unquiet Garves</option>
<option value="22">Tower Ruins</option>
<option value="297">Twin Peak</option>
<option value="100">Whitey's Grove</option>
</select>
</form>

<form method="post" action="choice.php">
<input type="hidden" name="option" value="3" />
<input type="hidden" name="pwd" value="923738632155532b6a3b80050d0b0298" />
<input type="hidden" name="whichchoice" value="1483" />
<input type="submit" class="button" value="Back to Inventory" />
</form>
</center>
</td></tr></table></center></td></tr><tr><td height=4></td></tr></table><script>top.charpane.location.href="charpane.php";</script></body></html>