Hello, I stumbled upon a potential problem with the URL parsing in the chat:
It seems that the parsing of board positions has higher precedence than that of the URLs.
An URL with encoded arguments that match board positions won’t render correctly: eg.:
https://something.com?some%20string%C3%B3
I don’t know if it worth fixing. I just thought it might be of interest to someone.
3 Likes
Here’s the ordered regexes, general url indeed last.
/*
* Copyright (C) 2012-2020 Online-Go.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import * as React from "react";
import { _ } from "translate";
import { Link } from "react-router-dom";
This file has been truncated. show original
2 Likes
esoka
March 6, 2022, 12:16pm
4
I don’t see move parsing in this one though. Is it passed as the extra replacements argument?
The move number on the end of the game number? Here’s the diff which added that.
committed 02:33PM - 20 Jun 21 UTC
esoka
March 6, 2022, 1:25pm
6
Not that. The one that parses C3 and then places it as an object that you can hover over to see the coordinate on the board. Like so (url form OP)
These regex are for urls only as well as @ and # it seems.
I believe additional replacements are specified for game chat:
}
}
export class GameChatLine extends React.Component<GameChatLineProperties> {
//scrolled_to_bottom:any = {"malkovich": true, "main": true};
constructor(props) {
super(props);
}
markup(body): JSX.Element | Array<JSX.Element> {
if (typeof body === "string") {
return chat_markup(body, [
{
split: /(\b[a-zA-Z][0-9]{1,2}\b)/gm,
pattern: /\b([a-zA-Z][0-9]{1,2})\b/gm,
replacement: (m, idx) => {
const pos = m[1];
if (parsePosition(pos).i < 0) {
return <span key={idx}>{m[1]}</span>;
}
esoka
March 6, 2022, 3:29pm
8
Yep that seems to be it. Seems like as I guessed it’s in the “extra replacements” and it’s just appended at the end, meaning it’s applied at the end too. I think links need to have priority over that but this design is bullet proof.