﻿# V8039\. Suspicious leading or trailing whitespace in the value used to identify an element\.

The analyzer has detected a string with a potentially incorrect leading or trailing whitespace character\.

Consider several examples that trigger this warning\.

The example N1:

```cpp
func buildRequestHeaders() {
  headers := map[string]string{
    "Content-Type": "application/json",
    "Accept ":      "application/json",
    "User-Agent":   "my-service/1.0",
    ....
  }
  ....
}
```

The `"Accept "` string key contains a trailing whitespace character\. If a value is retrieved via the `"Accept"` key \(without the whitespace\), it will not be found\.

To fix the issue, remove the whitespace:

```cpp
"Accept":      "application/json"
```

The example N2:

```cpp
func registerFlags() {
  debug := flag.Bool("debug", false, "enable debug logging")
  port := flag.Int(" port", 8080, "server port")

  flag.Parse()

  ....
}
```

The `" port"` flag name starts with the whitespace\. As a result, the flag will be registered with this exact name, and users cannot pass it in the expected way \(`--port`\)\.

To fix the issue, remove the whitespace:

```cpp
port := flag.Int("port", 8080, "server port")
```

The example N3: 

```cpp
func decodeUser() {
  type User struct {
    ID   int    `json:"id"`
    Name string `json:" name"`
  }

  u := User{
    ID:   1,
    Name: "Donald",
  }

  ....
}
```

The `json:"` name" tag value contains a leading whitespace character\. During JSON serialization and deserialization, the `" name"` key will be used instead of the expected `"name"` key\.

To fix the issue, remove the whitespace:

```cpp
Name string `json:"name"`
```