Skip to content

Commit

Permalink
UnrealURL: Copy urlString instead of taking a reference, and trim it …
Browse files Browse the repository at this point in the history
…to prevent a crash
  • Loading branch information
LupertEverett authored and dpjudas committed Apr 23, 2024
1 parent eeeeba7 commit dc2c941
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion SurrealEngine/UObject/UnrealURL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,17 @@ UnrealURL::UnrealURL(const UnrealURL& baseURL, const UnrealURL& nextURL)
Map = Map.substr(8);
}

UnrealURL::UnrealURL(const std::string& urlString)
UnrealURL::UnrealURL(std::string urlString)
{
// Expected url format on a local game:
// mapname[#teleporttag][?key1=value1[?key2=value2]...]

// Trim the url string of whitespaces
// Fixes the crash during the transition from Temple of Vandora to The Trench in Unreal
// Due to the exit teleporter pointing to " trench" (with the whitespace at the beginning)
urlString.erase(urlString.find_last_not_of(' ') + 1);
urlString.erase(0, urlString.find_first_not_of(' '));

std::string mapName = "";
std::string teleportTag = "";
std::string options = "";
Expand Down
2 changes: 1 addition & 1 deletion SurrealEngine/UObject/UnrealURL.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class UnrealURL
// Constructs an UnrealURL by passing the options from nextURL to the baseURL
UnrealURL(const UnrealURL& baseURL, const UnrealURL& nextURL);
// Constructs an UnrealURL from a given parse-able string.
UnrealURL(const std::string& urlString);
UnrealURL(std::string urlString);

void AddOrReplaceOption(const std::string& newvalue);
bool HasOption(const std::string& name) const;
Expand Down

0 comments on commit dc2c941

Please sign in to comment.