@PostMapping
    @Secured(resource = AuthConstants.CONSOLE_RESOURCE_NAME_PREFIX
            + "namespaces", action = ActionTypes.WRITE, signType = SignType.CONSOLE)
    public Result<Boolean> createNamespace(NamespaceForm namespaceForm) throws NacosException {
        
        namespaceForm.validate();
        
        String namespaceId = namespaceForm.getNamespaceId();
        String namespaceName = namespaceForm.getNamespaceName();
        String namespaceDesc = namespaceForm.getNamespaceDesc();
        
        if (StringUtils.isBlank(namespaceId)) {
            namespaceId = UUID.randomUUID().toString();
        } else {
            namespaceId = namespaceId.trim();
            if (!namespaceIdCheckPattern.matcher(namespaceId).matches()) {
                throw new NacosApiException(HttpStatus.BAD_REQUEST.value(), ErrorCode.ILLEGAL_NAMESPACE,
                        "namespaceId [" + namespaceId + "] mismatch the pattern");
            }
            if (namespaceId.length() > NAMESPACE_ID_MAX_LENGTH) {
                throw new NacosApiException(HttpStatus.BAD_REQUEST.value(), ErrorCode.ILLEGAL_NAMESPACE,
                        "too long namespaceId, over " + NAMESPACE_ID_MAX_LENGTH);
            }
            // check unique
            if (namespacePersistService.tenantInfoCountByTenantId(namespaceId) > 0) {
                throw new NacosApiException(HttpStatus.BAD_REQUEST.value(), ErrorCode.ILLEGAL_NAMESPACE,
                        "the namespaceId is existed, namespaceId: " + namespaceForm.getNamespaceId());
            }
        }
        // contains illegal chars
        if (!namespaceNameCheckPattern.matcher(namespaceName).matches()) {
            throw new NacosApiException(HttpStatus.BAD_REQUEST.value(), ErrorCode.ILLEGAL_NAMESPACE,
                "namespaceName [" + namespaceName + "] contains illegal char");
        }
        return Result.success(namespaceOperationService.createNamespace(namespaceId, namespaceName, namespaceDesc));
    }
@Test
    void testEditNamespaceWithIllegalName() {
        NamespaceForm form = new NamespaceForm();
        form.setNamespaceId("test-id");
        form.setNamespaceDesc("testDesc");
        
        form.setNamespaceName("test@Name");
        assertThrows(NacosException.class, () -> namespaceControllerV2.createNamespace(form));
        
        form.setNamespaceName("test#Name");
        assertThrows(NacosException.class, () -> namespaceControllerV2.createNamespace(form));
        
        form.setNamespaceName("test$Name");
        assertThrows(NacosException.class, () -> namespaceControllerV2.createNamespace(form));
        
        form.setNamespaceName("test%Name");
        assertThrows(NacosException.class, () -> namespaceControllerV2.createNamespace(form));
        
        form.setNamespaceName("test^Name");
        assertThrows(NacosException.class, () -> namespaceControllerV2.createNamespace(form));
        
        form.setNamespaceName("test&Name");
        assertThrows(NacosException.class, () -> namespaceControllerV2.createNamespace(form));
        
        form.setNamespaceName("test*Name");
        assertThrows(NacosException.class, () -> namespaceControllerV2.createNamespace(form));
    }