Don't automatically convert OpenStreetMap URLs into geo: URIs in sent messages

Updates #1850 and #2914
This commit is contained in:
JC Brand 2022-05-11 10:01:18 +02:00
parent a57853156e
commit ab7e879261
7 changed files with 26 additions and 29 deletions

View File

@ -1,5 +1,9 @@
# Changelog
## 10.0.0 (Unreleased)
- Don't automatically convert OpenStreetMap URLs into `geo:` URIs in sent messages
## 9.1.1 (2022-05-05)
- GIFs don't render inside unfurls and cause a TypeError

View File

@ -889,7 +889,7 @@ const ChatBox = ModelWithContact.extend({
const is_spoiler = !!this.get('composing_spoiler');
const origin_id = u.getUniqueId();
const text = attrs?.body;
const body = text ? u.httpToGeoUri(u.shortnamesToUnicode(text), _converse) : undefined;
const body = text ? u.shortnamesToUnicode(text) : undefined;
attrs = Object.assign({}, attrs, {
'from': _converse.bare_jid,
'fullname': _converse.xmppstatus.get('fullname'),

View File

@ -987,7 +987,7 @@ const ChatRoomMixin = {
[text, references] = this.parseTextForReferences(attrs.body);
}
const origin_id = getUniqueId();
const body = text ? u.httpToGeoUri(u.shortnamesToUnicode(text), _converse) : undefined;
const body = text ? u.shortnamesToUnicode(text) : undefined;
attrs = Object.assign({}, attrs, {
body,
is_spoiler,

View File

@ -13,7 +13,7 @@
* @property { String } [credentials_url] - URL from where login credentials can be fetched
* @property { Boolean } [discover_connection_methods=true]
* @property { RegExp } [geouri_regex]
* @property { RegExp } [geouri_replacement='https - //www.openstreetmap.org/?mlat=$1&mlon=$2#map=18/$1/$2']
* @property { RegExp } [geouri_replacement='https://www.openstreetmap.org/?mlat=$1&mlon=$2#map=18/$1/$2']
* @property { String } [i18n]
* @property { String } [jid]
* @property { Boolean } [keepalive=true]

View File

@ -459,11 +459,6 @@ export function getUniqueId (suffix) {
}
}
u.httpToGeoUri = function(text) {
const replacement = 'geo:$1,$2';
return text.replace(settings_api.get("geouri_regex"), replacement);
};
/**
* Clears the specified timeout and interval.

View File

@ -262,6 +262,23 @@ describe("A Chat Message", function () {
expect(_converse.api.chatboxes.get).not.toHaveBeenCalled();
}));
it("will render Openstreetmap-URL from geo-URI",
mock.initConverse(['chatBoxesFetched'], {}, async function (_converse) {
await mock.waitForRoster(_converse, 'current', 1);
const message = "geo:37.786971,-122.399677";
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
await mock.openChatBoxFor(_converse, contact_jid);
const view = _converse.chatboxviews.get(contact_jid);
spyOn(view.model, 'sendMessage').and.callThrough();
await mock.sendMessage(view, message);
await u.waitUntil(() => view.querySelectorAll('.chat-content .chat-msg').length, 1000);
expect(view.model.sendMessage).toHaveBeenCalled();
const msg = sizzle('.chat-content .chat-msg:last .chat-msg__text', view).pop();
await u.waitUntil(() => msg.innerHTML.replace(/\<!-.*?-\>/g, '') ===
'<a target="_blank" rel="noopener" href="https://www.openstreetmap.org/?mlat=37.786971&amp;'+
'mlon=-122.399677#map=18/37.786971/-122.399677">https://www.openstreetmap.org/?mlat=37.786971&amp;mlon=-122.399677#map=18/37.786971/-122.399677</a>');
}));
it("can be a carbon message, as defined in XEP-0280",
mock.initConverse([], {}, async function (_converse) {
@ -799,6 +816,7 @@ describe("A Chat Message", function () {
"Another message within 10 minutes, but from a different person");
jasmine.clock().uninstall();
}));

View File

@ -1,8 +1,6 @@
/*global mock, converse */
const $msg = converse.env.$msg;
const u = converse.env.utils;
const sizzle = converse.env.sizzle;
const { $msg, u } = converse.env;
describe("A chat message", function () {
@ -206,24 +204,6 @@ describe("A Minimized ChatBoxView's Unread Message Count", function () {
expect(u.isVisible(unread_count)).toBeTruthy();
expect(unread_count.innerHTML.replace(/<!-.*?->/g, '')).toBe('1');
}));
it("will render Openstreetmap-URL from geo-URI",
mock.initConverse(['chatBoxesFetched'], {}, async function (_converse) {
await mock.waitForRoster(_converse, 'current', 1);
const message = "geo:37.786971,-122.399677";
const contact_jid = mock.cur_names[0].replace(/ /g,'.').toLowerCase() + '@montague.lit';
await mock.openChatBoxFor(_converse, contact_jid);
const view = _converse.chatboxviews.get(contact_jid);
spyOn(view.model, 'sendMessage').and.callThrough();
await mock.sendMessage(view, message);
await u.waitUntil(() => view.querySelectorAll('.chat-content .chat-msg').length, 1000);
expect(view.model.sendMessage).toHaveBeenCalled();
const msg = sizzle('.chat-content .chat-msg:last .chat-msg__text', view).pop();
await u.waitUntil(() => msg.innerHTML.replace(/\<!-.*?-\>/g, '') ===
'<a target="_blank" rel="noopener" href="https://www.openstreetmap.org/?mlat=37.786971&amp;'+
'mlon=-122.399677#map=18/37.786971/-122.399677">https://www.openstreetmap.org/?mlat=37.786971&amp;mlon=-122.399677#map=18/37.786971/-122.399677</a>');
}));
});