Skip to content

Commit

Permalink
Correctly handle comma separated groups where the group name might in…
Browse files Browse the repository at this point in the history
…clude , and \

Signed-off-by: Arne Hamann <[email protected]>
  • Loading branch information
tacruc committed Mar 23, 2023
1 parent 62dcb1d commit a262835
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
5 changes: 2 additions & 3 deletions src/components/map/ContactsLayer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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) {
Expand Down
16 changes: 16 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -382,6 +397,7 @@ export const accented = {
export {
basename,
dirname,
splitByNonEscapedComma,
Timer,
getLetterColor,
hslToRgb,
Expand Down
12 changes: 3 additions & 9 deletions src/views/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -1399,10 +1396,7 @@ export default {
c.groupList = []
if (c.GROUPS) {
try {
// const cGroups = c.GROUPS.split(/(?<!\\),/).map((name) => {
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)
Expand Down

0 comments on commit a262835

Please sign in to comment.