Skip to content

Commit

Permalink
Make blank malformed tile links from server render properly in browser
Browse files Browse the repository at this point in the history
  • Loading branch information
Lexxie9952 committed May 19, 2020
1 parent 1c4dafa commit 0e9847d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions freeciv-web/src/main/webapp/javascript/messages.js
Expand Up @@ -400,6 +400,10 @@ function update_chatbox(messages)
item.style.paddingLeft = "30px";
}

// Intercept server-side tile links
if (messages[i].message.includes("<l tgt="))
messages[i].message = parseServerLink(messages[i].message);

item.innerHTML = messages[i].message;
scrollDiv.appendChild(item);
}
Expand All @@ -422,6 +426,24 @@ function update_chatbox(messages)
}
}

/**************************************************************************
Intercepts blank server side tile links and forms them properly.
This fixes a bug where server sends us malformed link such as
<l tgt=\"tile\" x=0 y=11 />. which browser renders as:
<l tgt="tile" x=0 y=11>.</l> ... but should be:
<l tgt="tile" x=0 y=11>(0,11)</l>
**************************************************************************/
function parseServerLink(message)
{
if (message.includes(" />.</")) { // empty tile link with no coordinates
var x = message.match(/x=(.*?) y=/)[1];
var y = message.match(/y=(.*?) \/>.</)[1];
const fcol = "<font style='text-decoration: underline;' color='#1FDFFF'>"
message = message.replace(/ \/>.<\//, ">"+fcol+"("+x+","+y+")</font></l></");
}
return message;
}

/**************************************************************************
Used to keep the chatbox scroll position fresh.
**************************************************************************/
Expand Down

1 comment on commit 0e9847d

@Lexxie9952
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixing this on server side caused unexpected server crash... other things in the server are dependent on the ... /> with unclosed tag, apparently.

Please sign in to comment.