Skip to content

Support multi-line strings in Database rules JSON #308

Closed

Description

@wincentj

I'm trying to do a simple database rules deploy using version 3.6.0 and I recieve the following error on the CL.

Error: There was an error loading firebase.json:

Unexpected token ' ' at 6:35
      ".write": "data.exists() &&
                                 ^
Having trouble? Try firebase deploy --help

My rules are saved in a file 'database_rules.json', my firebase.json file looks like this:

{
  "rules": "database_rules.json",
  "hosting": {
    "public": "./",
    "ignore": [
      "firebase.json",
      "**/.*",
      "**/node_modules/**",
      "functions",
      "gulpfile.js"
    ]
  }
}

My rules are the following:

{
  "rules": {
    ".validate": "auth !== null",
    "_const": {
      ".read":"true",
      ".write": "data.exists() &&
          newData.exists()"
    }
  }
}

I was under the impression multi-line strings were OK, as they publish fine in the rules editor on the console. If this is intended, what's the work-around to get this to deploy whilst preserving the newlines so they stay readable in the console?

Activity

  1. mbleigh commented on Apr 11, 2017

    @mbleigh
    Contributor

    Multi-line strings are not currently supported by the CLI when deploying rules. I'll change the title of this to reflect that as a bug/feature request.

  2. changed the title [-]firebase deploy --only database issue ?[/-] [+]Support multi-line strings in Database rules JSON[/+] on Apr 11, 2017
  3. wincentj commented on Apr 11, 2017

    @wincentj
    Author

    Got it. Thanks!

  4. eliezedeck commented on Jun 2, 2017

    @eliezedeck

    To add to this, I think the fact that it mentions firebase.json instead of the actual file that it doesn't like is misleading.

    Naturally, people will look at the mentioned file, yet, the problem isn't really there. It is actually in the database.rules.json. While firebase.json read the file in the {"database": {"rules": "..."}, it should mention that the problem lyes in the referenced file.

    This could be one of these cases where the tool confuses the developer instead of helping.

  5. nathanvogel commented on Jul 25, 2017

    @nathanvogel

    This would also make my life easier 👍

  6. added a commit that references this issue on Sep 27, 2018
  7. danielo515 commented on Apr 4, 2021

    @danielo515

    So it is now possible to use multiline strings on the database.rules.json? Any recommendation to make it work on VSCode? It is not valid JSON so we can not use JSON as file type

  8. samtstern commented on Apr 6, 2021

    @samtstern
    Contributor

    @danielo515 a good trick is to set your syntax highlighter in VSCode (or any IDE) to treat the rules JSON file as a JavaScript file.

  9. danielo515 commented on Apr 8, 2021

    @danielo515

    Thanks for the tip @samtstern but how that helps? Broken strings are also a syntax error on JS unless you use inverted ticks
    ``
    And if that is supported inside a JSON file, at that point the file may be better defined as a JS file insted

  10. added a commit that references this issue on Sep 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions