question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

az tag remove-value trims spaces

See original GitHub issue

Describe the bug When running: az tag remove-value --name 'TagName' --value 'TagValue' --subscription "SubscriptionName", if Tagvalue ends with a space, the space is trimmed.

Also note that symbols (like %) are double encoded.

To Reproduce See above

Expected behavior The space should not be trimmed.

Environment summary Windows Powershell

Additional context Both symbols and spaces are supported when creating tags (via the UI and ARM at least)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:11 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jiaslicommented, Apr 29, 2020

What Azure Portal creates is not a predefined tag which can’t be edited by Azure CLI. For example, I added a tag testtag to a resource group in Azure Portal, then run

> az tag add-value -n testtag --value "value2 "
Predefined tag name 'testtag' could not be found.

Create a predefined tag with CLI:

> az tag create -n pretag
{
  "count": {
    "type": "Total",
    "value": 0
  },
  "id": "/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590/tagNames/pretag",
  "tagName": "pretag",
  "values": []
}

Then add value with space to it:

> az tag add-value -n pretag --value "value1 " --debug
Command arguments: ['tag', 'add-value', '-n', 'pretag', '--value', 'value1 ', '--debug']

msrest.http_logger : Request URL: 'https://management.azure.com/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590/tagNames/pretag/tagValues/value1%20?api-version=2019-07-01'
msrest.http_logger : Request method: 'PUT'
msrest.http_logger : Request body:
msrest.http_logger : None

msrest.http_logger : Response status: 201
msrest.http_logger : Response content:
msrest.http_logger : {"id":"/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590/tagNames/pretag/tagValues/value1","tagValue":"value1","count":{"type":"Total","value":0}}
{
  "count": {
    "type": "Total",
    "value": 0
  },
  "id": "/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590/tagNames/pretag/tagValues/value1",
  "tagValue": "value1"
}

Note that the space %20 does appear in the URL https://management.azure.com/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590/tagNames/pretag/tagValues/value1%20 for Tags - Create Or Update Value REST API, but is discarded in the response "tagValue":"value1".

However, if the value is added by directly adding a name: value tag to a resource group, it can retain the space with "pretag": "value2 ":

> az group show -g rg1
{
  "id": "/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590/resourceGroups/rg1",
  "location": "southeastasia",
  "managedBy": null,
  "name": "rg1",
  "properties": {
    "provisioningState": "Succeeded"
  },
  "tags": {
    "pretag": "value2 "
  },
  "type": "Microsoft.Resources/resourceGroups"
}

The space is also retained when showing the tag:

> az tag list --query "[?tagName=='pretag']"
[
  {
    "count": {
      "type": "Total",
      "value": 1
    },
    "id": "/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590/tagNames/pretag",
    "tagName": "pretag",
    "values": [
      {
        "count": {
          "type": "Total",
          "value": 0
        },
        "id": "/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590/tagNames/pretag/tagValues/value1",
        "tagValue": "value1"
      },
      {
        "count": {
          "type": "Total",
          "value": 1
        },
        "id": "/subscriptions/0b1f6471-1bf0-4dda-aec3-cb9272f09590/tagNames/pretag/tagValues/value2 ",
        "tagValue": "value2 "
      }
    ]
  }
]

There may be some limitation or transformation on the on service API. @zhoxing-ms, I think we may need to confirm with service team whether this is by design.

0reactions
msftbot[bot]commented, May 10, 2022

Hi, we’re sending this friendly reminder because we haven’t heard back from you in a while. We need more information about this issue to help address it. Please be sure to give us your input within the next 7 days. If we don’t hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Space separated values; how to provide a value containing a ...
My goal is to store multiple tags in a variable and provide that variable to the --tags option of several az commands in...
Read more >
js to remove value Code Example - Code Grepper
“js to remove value” Code Answer · how to remove a specific element from array in javascript · Browse Javascript Answers by Framework....
Read more >
Removing Leading and Trailing Spaces in Excel & Google Docs
The Trim function. The most obvious (and generally efficient) method for removing both leading and trailing space is to use the TRIM() ...
Read more >
vim book - Startitup
Jump to a subject: Position the cursor on a tag between | bars | and hit CTRL-]. With the mouse: ... < command...
Read more >
Pandas remove special characters from column names
First, specify the trim_character, which is the character that the TRIM ... Let's finish cleaning our column labels by: Replacing spaces with underscores....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found