Fixed link-handling for self-referential links in chat
This commit is contained in:
parent
13e2b9fe11
commit
3b113df86a
1 changed files with 13 additions and 1 deletions
|
|
@ -14,6 +14,9 @@ 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 <https://www.gnu.org/licenses/>.*/
|
||||
|
||||
//Config
|
||||
const config = require('../../config.json');
|
||||
|
||||
//NPM Imports
|
||||
const validator = require('validator');//No express here, so regular validator it is!
|
||||
const {sanitizeUrl} = require("@braintree/sanitize-url");
|
||||
|
|
@ -32,6 +35,15 @@ module.exports.cache = new Map();
|
|||
module.exports.markLink = async function(dirtyLink){
|
||||
const link = sanitizeUrl(dirtyLink);
|
||||
|
||||
//If this link is referencing this web server
|
||||
if(link.match(new RegExp(`^${config.protocol}://${config.domain}`)) != null){
|
||||
//Lazily return it as a good link, since we know it'll at least return a good 404 page XP
|
||||
return {
|
||||
link,
|
||||
type: "link"
|
||||
}
|
||||
}
|
||||
|
||||
//Check link cache for the requested link
|
||||
const cachedLink = module.exports.cache.get(link);
|
||||
|
||||
|
|
@ -105,4 +117,4 @@ module.exports.markLink = async function(dirtyLink){
|
|||
|
||||
//return the link
|
||||
return linkObj;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue