diff --git a/src/components/map/ContactsLayer.vue b/src/components/map/ContactsLayer.vue index f5c8ab13c..fd1d24145 100644 --- a/src/components/map/ContactsLayer.vue +++ b/src/components/map/ContactsLayer.vue @@ -20,6 +20,7 @@ import Vue2LeafletMarkerCluster from 'vue2-leaflet-markercluster' import ContactLayer from './ContactLayer' import optionsController from '../../optionsController' import {getToken, isPublic} from "../../utils/common"; +import {splitByNonEscapedComma} from "../../utils"; const CONTACT_MARKER_VIEW_SIZE = 40 @@ -63,9 +64,7 @@ export default { return this.contacts.filter((c) => { if (c.GROUPS) { try { - const cGroups = c.GROUPS.split(/[^\\],/).map((name) => { - return name.replace('\\,', ',') - }) + const cGroups = splitByNonEscapedComma(c.GROUPS) for (let i = 0; i < cGroups.length; i++) { // if at least in one enabled group if (this.groups[cGroups[i]].enabled) { diff --git a/src/utils.js b/src/utils.js index 09f7f6ae2..854f511a7 100644 --- a/src/utils.js +++ b/src/utils.js @@ -9,6 +9,21 @@ function dirname(path) { return path.replace(/\\/g, '/').replace(/\/[^\/]*$/, ''); } +function splitByNonEscapedComma(str) { + // As safari doesn't support lookbehind we need to work with reversed strings + return str.split('') + .reverse() + .join('') + .split(/,(?!(?:(?:\\\\)*\\(?!\\)))/) + .map((g) => { + return g.replaceAll(',\\',',') + .replaceAll('\\\\','\\') + .split('') + .reverse() + .join('') + }).reverse() +} + function Timer(callback, mydelay) { var timerId, start, @@ -382,6 +397,7 @@ export const accented = { export { basename, dirname, + splitByNonEscapedComma, Timer, getLetterColor, hslToRgb, diff --git a/src/views/App.vue b/src/views/App.vue index a88c82b03..4a51a7f8f 100644 --- a/src/views/App.vue +++ b/src/views/App.vue @@ -230,11 +230,10 @@ import AppNavigationTracksItem from '../components/AppNavigationTracksItem' import AppNavigationDevicesItem from '../components/AppNavigationDevicesItem' import AppNavigationMyMapsItem from '../components/AppNavigationMyMapsItem' import optionsController from '../optionsController' -import { getLetterColor, hslToRgb, Timer, getDeviceInfoFromUserAgent2, isComputer, isPhone } from '../utils' +import { getLetterColor, hslToRgb, Timer, getDeviceInfoFromUserAgent2, isComputer, isPhone, splitByNonEscapedComma } from '../utils' import { binSearch, getToken, isPublic } from '../utils/common' import { poiSearchData } from '../utils/poiData' import { processGpx } from '../tracksUtils' - import L from 'leaflet' import { geoToLatLng, getFormattedADR } from '../utils/mapUtils' import * as network from '../network' @@ -1316,9 +1315,7 @@ export default { const contactsInGroup = this.contacts.filter((c) => { if (c.GROUPS) { try { - const cGroups = c.GROUPS.split(/[^\\],/).map((name) => { - return name.replace('\\,', ',') - }) + const cGroups = splitByNonEscapedComma(c.GROUPS) for (let i = 0; i < cGroups.length; i++) { // if at least in one enabled group if (cGroups[i] === group) { @@ -1399,10 +1396,7 @@ export default { c.groupList = [] if (c.GROUPS) { try { - // const cGroups = c.GROUPS.split(/(? { - const cGroups = c.GROUPS.split(/[^\\],/).map((name) => { - return name.replace('\\,', ',') - }) + const cGroups = splitByNonEscapedComma(c.GROUPS) if (cGroups.length > 0) { cGroups.forEach((g) => { c.groupList.push(g)