TryGhost / TryGhost/NQL

Better string support (double quotes or escaped singles)

Open
#18 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug enhancement
Dominant language
JavaScript
Stars
7
Forks
7
Avg merge
9h 4m
Merged PRs (30d)
22

Description

NQL works mostly on literals - strings that don't need to be quoted because they are obviously strings.

E.g. tag:photo, we don't need to do tag:'photo', it's totally redundant!

However, if a string contains a character that has another purpose in NQL, we have to use quotes (or escaping) to make it clear the whole thing is intended as a string.

E.g. in a date string published_at:<2017-09-01 12:45:12, both the space and the colons mean that we cannot use a literal, and we need to use quotes e.g. published_at:<'2017-09-01 12:45:12'.

NOTE: should colons be allowed inside of literals?! Or should they be allowed as escaped-chars!??!

This works absolutely wonderfully if the filter lives in a URL encoded URL string, or in JSON, but poses a problem in javascript code:

Example from the prev/next helper in Ghost:

  apiOptions = {
            include: 'author,tags',
            order: 'published_at ' + order,
            limit: 1,
            filter: "slug:-" + slug + "+published_at:" + op + "'" + publishedAt + "'", // jscs:ignore
        }

Normally we would use single quotes around the code, but we can't because this would clash with NQL.

In other languages, you'd switch to using double quotes, but NQL doesn't support this.

If we switch to using template literals:

  apiOptions = {
            filter: `slug:-${slug}+published_at:${op}'${publishedAt}'`, // jscs:ignore
}

The single quotes end up escaped like \' inside the string, which NQL also doesn't seem to understand - or it goes wrong somewhere on the way to NQL - need to test this better to understand what's happening - it definitely should work

TODO:

  • At least support escaped single quotes (this is a bug)
  • Consider supporting double quotes (this is an enhancement)

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the escaped-single-quote case from the JavaScript apiOptions example and compare it with the existing NQL literal behavior. Resolve whether colons remain literal characters, then verify that escaped single quotes work and that double-quoted strings behave consistently if included.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.