commit d3c2cb24c8a8bbf0b289aa9c2ea19def2c91d53d
parent b765a9631528b4eb3f55fb2c193d21432d918550
Author: Sergej Orlov <wladimirych@gmail.com>
Date: Fri, 6 Dec 2024 16:14:38 +0100
search: remove support for short Yandex links
Yandex server blocks requests via proxy
Diffstat:
2 files changed, 3 insertions(+), 38 deletions(-)
diff --git a/src/lib/leaflet.control.search/providers/links.js b/src/lib/leaflet.control.search/providers/links.js
@@ -45,36 +45,14 @@ const YandexMapsUrl = {
},
getResults: async function (url) {
- let isShort = false;
- let actualUrl;
try {
- if (url.pathname.match(/^\/maps\/-\//u)) {
- isShort = true;
- const pageText = (await fetch(urlViaCorsProxy(url.toString()))).response;
- try {
- const dom = new DOMParser().parseFromString(pageText, 'text/html');
- actualUrl = new URL(dom.querySelector('meta[property="og:image:secure_url"]').content);
- } catch (_) {
- let propertyContent = pageText.match(
- /<meta\s+property\s*=\s*["']?og:image:secure_url["']?\s+content\s*=\s*["']?([^"' >]+)/u
- )[1];
- propertyContent = propertyContent.replaceAll('&', '&');
- actualUrl = new URL(decodeURIComponent(propertyContent));
- }
- } else {
- actualUrl = url;
- }
- const paramLl = actualUrl.searchParams.get('ll');
- const paramZ = actualUrl.searchParams.get('z');
+ const paramLl = url.searchParams.get('ll');
+ const paramZ = url.searchParams.get('z');
const [lon, lat] = paramLl.split(',').map(parseFloat);
const zoom = Math.round(parseFloat(paramZ));
return makeSearchResults(lat, lon, zoom, 'Yandex map view');
} catch (_) {
- return {
- error: L.Util.template(isShort ? MESSAGE_SHORT_LINK_MALFORMED : MESSAGE_LINK_MALFORMED, {
- name: 'Yandex',
- }),
- };
+ return {error: L.Util.template(MESSAGE_LINK_MALFORMED, {name: 'Yandex'})};
}
},
};
diff --git a/test/test_search_links.js b/test/test_search_links.js
@@ -33,18 +33,6 @@ suite('LinksProvider - parsing valid links');
[{title: 'Yandex map view', latlng: {lat: 49.219896, lng: 16.548629}, zoom: 14}],
],
[
- 'https://yandex.ru/maps/-/CCQpqZXJCB',
- [{title: 'Yandex map view', latlng: {lat: 49.219896, lng: 16.548629}, zoom: 14}],
- ],
- [
- 'https://yandex.ru/maps/-/CCQpqZdgpA',
- [{title: 'Yandex map view', latlng: {lat: 49.219896, lng: 16.548629}, zoom: 14}],
- ],
- [
- 'https://yandex.ru/maps/-/CCQpqZhrsB',
- [{title: 'Yandex map view', latlng: {lat: 49.219896, lng: 16.548629}, zoom: 14}],
- ],
- [
'https://www.openstreetmap.org/#map=14/49.2199/16.5486',
[{title: 'OpenStreetMap view', latlng: {lat: 49.2199, lng: 16.5486}, zoom: 14}],
],
@@ -213,7 +201,6 @@ suite('LinksProvider - parse invalid links');
['https://example.com/#l=O&m=99/49.44893/52.5547', 'Unsupported link'],
['https://en.mapy.cz/s/lucacunom', 'Broken Mapy.cz short link'],
['https://goo.gl/maps/ZvjVBY78HUP8HjQi', 'Broken Google short link'],
- // ['https://yandex.ru/maps/-/CCQpqZXJ', 'Broken Yandex short link'], // Yandex returns good result for broken link
].forEach(function ([query, expectedError]) {
test(`Invalid link ${query}`, async function () {
assert.isTrue(links.isOurQuery(query));