Skip to content

Commit

Permalink
Fix polynomial regexp
Browse files Browse the repository at this point in the history
  • Loading branch information
akvlad committed Aug 21, 2024
1 parent 4720bac commit 433173f
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pyroscope/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,18 +214,21 @@ function sizeToBackfill (startMs, endMs, stepSec) {
*/
const parseQuery = (query) => {
query = query.trim()
const match = query.match(/^([^{]+)\s*(\{(.*)})?$/)
const match = query.match(/^([^{\s]+)\s*(\{(.*)})?$/)
if (!match) {
return null
}
const typeId = match[1]
const typeDesc = parseTypeId(typeId)
const strLabels = match[3] || ''
let strLabels = (match[3] || '').trim()
const labels = []
if (strLabels && strLabels !== '') {
for (const m in strLabels.matchAll(/([,{])\s*([^A-Za-z0-9_]+)\s*(!=|!~|=~|=)\s*("([^"\\]|\\.)*")/g)) {
labels.push([m[2], m[3], m[4]])
while (strLabels && strLabels !== '' && strLabels !== '}') {
const m = strLabels.match(/^([,{])\s*([A-Za-z0-9_]+)\s*(!=|!~|=~|=)\s*("([^"\\]|\\.)*")/)
if (!m) {
throw new Error('Invalid label selector')
}
labels.push([m[2], m[3], m[4]])
strLabels = strLabels.substring(m[0].length).trim()
}
const profileType = new types.ProfileType()
profileType.setId(typeId)
Expand Down

0 comments on commit 433173f

Please sign in to comment.