{"record":{"id":"71e9d59ba8a3da42","repo":"nats-io/nats-server","slug":"wildcards-not-allowed-in-publish-s-topic-q","errorCode":null,"errorMessage":"wildcards not allowed in publish's topic: %q","messagePattern":"wildcards not allowed in publish's topic: %q","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/mqtt.go","lineNumber":6251,"sourceCode":"\t\t\t// nodes) where the resulting control line could be split.\n\t\t\treturn nil, errMQTTUnsupportedCharacters\n\t\tcase 0x7f:\n\t\t\t// SubjectTree uses DEL as an internal pivot marker, so retained\n\t\t\t// subjects containing it cannot be indexed safely, including\n\t\t\t// legacy retained messages recovered from the retained-message\n\t\t\t// stream.\n\t\t\treturn nil, errMQTTUnsupportedCharacters\n\t\tcase btsep:\n\t\t\tif !cp {\n\t\t\t\tmakeCopy(i)\n\t\t\t}\n\t\t\tres = append(res, mqttTopicLevelSep, mqttTopicLevelSep)\n\t\t\tj++\n\t\tcase mqttSingleLevelWC, mqttMultiLevelWC:\n\t\t\tif !wcOk {\n\t\t\t\t// Spec [MQTT-3.3.2-2] and [MQTT-4.7.1-1]\n\t\t\t\t// The wildcard characters can be used in Topic Filters, but MUST NOT be used within a Topic Name\n\t\t\t\treturn nil, fmt.Errorf(\"wildcards not allowed in publish's topic: %q\", mt)\n\t\t\t}\n\t\t\tif !cp {\n\t\t\t\tmakeCopy(i)\n\t\t\t}\n\t\t\tif mt[i] == mqttSingleLevelWC {\n\t\t\t\tres = append(res, pwc)\n\t\t\t} else {\n\t\t\t\tres = append(res, fwc)\n\t\t\t}\n\t\tdefault:\n\t\t\tif cp {\n\t\t\t\tres = append(res, mt[i])\n\t\t\t}\n\t\t}\n\t\tj++\n\t}\n\tif cp && res[j-1] == btsep {\n\t\tres = append(res, mqttTopicLevelSep)","sourceCodeStart":6233,"sourceCodeEnd":6269,"githubUrl":"https://github.com/nats-io/nats-server/blob/3a66a489d262bf89b71a71c955c94920394532f3/server/mqtt.go#L6233-L6269","documentation":"MQTT topic validation for PUBLISH (specs MQTT-3.3.2-2 and MQTT-4.7.1-1): the topic being published contains wildcard characters (+ or #), which are only permitted in subscriptions, never in publishes.","triggerScenarios":"Thrown at server/mqtt.go:6251 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Publish to a concrete topic without + or #","Use wildcards only in SUBSCRIBE filters"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"3a66a489d262bf89b71a71c955c94920394532f3","analyzedAt":"2026-09-02T04:41:54.247Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}