Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does not correctly handle when a string starts with a bracket but does not end with a bracket #250

Open
1 of 2 tasks
StephenWeatherford opened this issue May 30, 2019 · 3 comments
Milestone

Comments

@StephenWeatherford
Copy link
Contributor

StephenWeatherford commented May 30, 2019

  • fix colorization
  • fix validation

See https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-group-authoring-templates#syntax:

To have a literal string start with a bracket [, but not have it interpreted as an expression, add an extra bracket to start the string with [[.

But it turns out you only need the [[ if your string starts with a bracket and ends with a bracket. I.e.:

"value": "[ChefInSpec]InstalledApplicationLinuxResource1;AttributesYmlContent"

is perfectly valid and is interpreted as a string, since it does not end with a bracket.

@StephenWeatherford
Copy link
Contributor Author

StephenWeatherford commented May 30, 2019

Example template that shows the rules:

{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "outputs": {
        ///////////////////////////////////////////////////////////////////////
        // 1: Starts with [ but doesn't end with ] -> it is an unchanged string
        "output1a": {
            "type": "string",
            "value": "[one]two" // -> string: "[one]two" 
        },
        "output1b": {
            "type": "string",
            "value": "[one]two" // -> string: "[one]two"
        },
        "output1c": {
            "type": "string",
            "value": "[abc]withsuffix" // -> string: "[abc]withsuffix"
        },
        "output1d": {
            "type": "string",
            "value": "[Preview]: Audit VMs with insecure password security settings" // -> string: "[Preview]: Audit VMs with insecure password security settings"
        },
        "output1e": {
            "type": "string",
            "value": "[abc" // -> string: "[abc"
        },
        "output1f": {
            "type": "string",
            "value": "[[one]two" // -> string: "[[one]two"
        },

        ///////////////////////////////////////////////////////////////////////
        // 2: Starts with [[ but doesn't end with ] -> it is an (unchanged) string
        "output2a": {
            "type": "string",
            "value": "[[abc" // -> string: "[[abc"
        },
        "output2b": {
            "type": "string",
            "value": "[[[abc" // -> string:  "[[[abc"
        },

        ///////////////////////////////////////////////////////////////////////
        // 3: Starts with [[ and ends with ] -> replace the first [, it is a string
        "output3a": {
            "type": "string",
            "value": "[[one]" // -> string: "[one]"
        },
        "output3b": {
            "type": "string",
            "value": "[[one]two]" // -> string: "[one]two]"
        },
        "output3c": {
            "type": "string",
            "value": "[[[one]two]" // -> string: "[[one]two]"
        },
        "output3d": {
            "type": "string",
            "value": "[[[abc]" // -> string:  "[[abc]"
        },

        ///////////////////////////////////////////////////////////////////////
        // 4: Starts with [ and ends with ] with no whitespace before or after -> it is an expression
        "output4a": {
            "type": "string",
            "value": "[concat('')]" // -> expression: ""
        },

        ///////////////////////////////////////////////////////////////////////
        // 5: Anything else is a string
        "output5a": {
            "type": "string",
            "value": " [one]" // Starts with whitespace -> string: " [one]"
        },
        "output5b": {
            "type": "string",
            "value": "[one] " // Ends with whitespace -> string: "[one] "
        }
    },
    "resources": []
}

Output:

% ./deploy-rg.sh bugs/250/250a.json
{- Finished ..
  "id": "...,
  "location": null,
  "name": "250a",
  "properties": {
    "correlationId": "...",
    "debugSetting": null,
    "dependencies": [],
    "duration": "PT2.0232502S",
    "error": null,
    "mode": "Incremental",
    "onErrorDeployment": null,
    "outputResources": [],
    "outputs": {
      "output1a": {
        "type": "String",
        "value": "[one]two"
      },
      "output1b": {
        "type": "String",
        "value": "[one]two"
      },
      "output1c": {
        "type": "String",
        "value": "[abc]withsuffix"
      },
      "output1d": {
        "type": "String",
        "value": "[Preview]: Audit VMs with insecure password security settings"
      },
      "output1e": {
        "type": "String",
        "value": "[abc"
      },
      "output1f": {
        "type": "String",
        "value": "[[one]two"
      },
      "output2a": {
        "type": "String",
        "value": "[[abc"
      },
      "output2b": {
        "type": "String",
        "value": "[[[abc"
      },
      "output3a": {
        "type": "String",
        "value": "[one]"
      },
      "output3b": {
        "type": "String",
        "value": "[one]two]"
      },
      "output3c": {
        "type": "String",
        "value": "[[one]two]"
      },
      "output3d": {
        "type": "String",
        "value": "[[abc]"
      },
      "output4a": {
        "type": "String",
        "value": ""
      },
      "output5a": {
        "type": "String",
        "value": " [one]"
      },
      "output5b": {
        "type": "String",
        "value": "[one] "
      }
    },
    "parameters": null,
    "parametersLink": null,
    "providers": [],
    "provisioningState": "Succeeded",
    "templateHash": "14695072742888142074",
    "templateLink": null,
    "timestamp": "2021-04-09T18:35:12.056666+00:00",
    "validatedResources": null
  },
  "resourceGroup": "deleteme",
  "tags": null,
  "type": "Microsoft.Resources/deployments"
}

@StephenWeatherford StephenWeatherford added this to the 0.7.0 vNext milestone May 30, 2019
sbuttar pushed a commit to sbuttar/vscode-azurearmtools that referenced this issue Jun 5, 2019
StephenWeatherford added a commit that referenced this issue Jul 18, 2019
* Fix #250, strings vs expressions boundary cases

* Simplify output of colorization tests

* lint?
@vscodebot vscodebot bot locked and limited conversation to collaborators Sep 1, 2019
@StephenWeatherford StephenWeatherford changed the title Does not correctly handle the case when a string starts with a bracket but does not end with a bracket Does not correctly handle colorization when a string starts with a bracket but does not end with a bracket Sep 9, 2019
StephenWeatherford added a commit that referenced this issue Sep 17, 2019
* Use standalone language server

* fix

* work

* suites work

* suites work

* work

* work

* Test format range

* lint

* work

* format range suites

* cleanup

* work

* Work on Mac

* schema validation tests

* fix suites

* fixes

* fix tree tests

* Fix colorization suites

* Fix more tests

* work on functional tests

* fix launch.json

* Working on expressions functional tests

* Expression suites

* Expression suites

* lint

* Change diagnostics source

* Fix lang server path

* Fix suites

* arrow functions

* Simplify output of colorization tests

* fix colorization results

* orphaned files

* Fix #250, strings vs expressions boundary cases

* Fix suite

* Fix suite

* fix suite

* Increase timeout again

work

* fix

* Update ui

* lint

* Fix path check

* PR fix

* Disable lang server tests for now

* Lang conf file must be copied to dist (#276)

* Lang conf file must be copied to dist

* PR fix

* Acquire .dotnet core and search further in file for schema

* Fix build, suites

* Improve language server error handling (#282)

* Always validate file if langid=ARM (#285)

* Always validate file if langid=ARM

* refactor

* Show warnings about --wait-for-debugger and custom lang serve path (#286)

* Clarify licensing for public repo, update version/readme/changelog for 0.7.0 (#283)

* Remove EULA (handled by LICENSE.md)

* Clarify licensing in README.md

* Bump version, update changelog/readme

* Additional changes

* grammar

* Acquire language server binaries during build (#289)

* Acquire language server binaries during build

* Update to get threading fix

* PR fix

* comment

* Fixes

* IMprove message

* Improve message
@StephenWeatherford
Copy link
Contributor Author

Mistakingly closed

@StephenWeatherford StephenWeatherford changed the title Does not correctly handle colorization when a string starts with a bracket but does not end with a bracket Does not correctly handle when a string starts with a bracket but does not end with a bracket Apr 24, 2020
@StephenWeatherford StephenWeatherford removed this from the 0.8.0 milestone Feb 24, 2021
@MarcusFelling MarcusFelling added this to the 0.15.1 milestone Mar 8, 2021
@StephenWeatherford
Copy link
Contributor Author

Decision:

  1. Must fix false positives
  2. Experiment to see if we can automatically add closing bracket when you insert the beginning bracket
  3. if not Updates required to readme #2, then use "hybrid" approach - internally treat strings starting with bracket as an expression but don't show any errors for them

@StephenWeatherford StephenWeatherford removed this from the 0.15.1 milestone Apr 15, 2021
@MarcusFelling MarcusFelling added this to the 0.15.2 milestone May 11, 2021
@MarcusFelling MarcusFelling modified the milestones: 0.15.2, 0.15.3 Jul 22, 2021
@MarcusFelling MarcusFelling modified the milestones: 0.15.3, 0.15.4 Sep 9, 2021
@StephenWeatherford StephenWeatherford modified the milestones: 0.15.5, 0.15.7 May 4, 2022
@StephenWeatherford StephenWeatherford modified the milestones: 0.15.7, 0.15.8 May 27, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants