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

[BUG] Incorrect calculation of expressions with contains() #2531

Closed
dmgonch opened this issue Nov 14, 2023 · 1 comment · Fixed by #2533
Closed

[BUG] Incorrect calculation of expressions with contains() #2531

dmgonch opened this issue Nov 14, 2023 · 1 comment · Fixed by #2533
Assignees
Labels
bug Something isn't working feature: pre-flight-expansion Issues relating to expansion of ARM and Bicep.
Milestone

Comments

@dmgonch
Copy link

dmgonch commented Nov 14, 2023

Existing rule

No response

Description of the issue

An expression that includes contains() seems to always returns true (at least in the repro below). See as well the correct result produced by az deployment group create --what-if ... command.

Error messages

The result of running repro steps below is incorrect - doesNotContain must be false

        "properties": {
            "doesNotContain": true,
            "doesContain": true,
            "indexOfSubstring": 1,
            "stringToCheck": "abcd",
            "stringToFind": "bc",

Reproduction

Create bug.bicep:

var stringToCheck = 'abcd'
var stringToFind = 'bc'
var doesNotContain = !(contains(stringToCheck, stringToFind))
var doesContain = contains(stringToCheck, stringToFind)
var indexOfSubstring = indexOf(stringToCheck, stringToFind)

#disable-next-line BCP081 no-deployments-resources
resource taskDeployment 'Microsoft.Resources/deployments@2020-10-01' = {
  name: 'name'
  properties: {
    mode: 'Incremental'
    template: {
      '$schema': 'https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#'
      contentVersion: '1.0.0.0'
      resources: [
        {
          apiVersion: '2019-12-01'
          type: 'Microsoft.ManagedIdentity/userAssignedIdentities'
          name: 'test'
          properties: {
            doesNotContain: doesNotContain
            doesContain: doesContain
            indexOfSubstring: indexOfSubstring
            stringToCheck: stringToCheck
            stringToFind: stringToFind
          }
        }
      ]
    }
  }
}

Running az deployment group create --what-if -x Ignore --subscription <SUB-ID> -g <RG-NAME> -f bug.bicep produces the correct result:

      properties.doesContain:      true
      properties.doesNotContain:   false
      properties.indexOfSubstring: 1
      properties.stringToCheck:    "abcd"
      properties.stringToFind:     "bc"

Version of PSRule

2.9.0

Version of PSRule for Azure

1.31.0

Additional context

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.3.4
PSEdition                      Core
GitCommitId                    7.3.4
OS                             Linux 5.10.102.1-microsoft-standard-WSL2 #1 SMP Wed Mar 2 00:30:59 UTC 2022
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
@dmgonch dmgonch added bug Something isn't working Needs: Triage 🔍 labels Nov 14, 2023
@BernieWhite BernieWhite self-assigned this Nov 14, 2023
@BernieWhite BernieWhite added this to the v1.31.1 milestone Nov 14, 2023
@BernieWhite BernieWhite added feature: pre-flight-expansion Issues relating to expansion of ARM and Bicep. and removed Needs: Triage 🔍 labels Nov 14, 2023
@BernieWhite
Copy link
Collaborator

@dmgonch Thanks for reporting the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working feature: pre-flight-expansion Issues relating to expansion of ARM and Bicep.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants