mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-10 18:35:06 +08:00
block whitespace in permission id
- blocked all whitespace - Update IntelliJ IDEA plugin message - Bump IntelliJ IDEA testing project version - Add tests for permission id
This commit is contained in:
parent
6bb0241eef
commit
d0b71b200f
@ -31,10 +31,10 @@ public data class PermissionId(
|
||||
@ResolveContext(PERMISSION_NAME) public val name: String,
|
||||
) {
|
||||
init {
|
||||
require(!namespace.contains(' ')) {
|
||||
require(namespace.none { it.isWhitespace() }) {
|
||||
"' ' is not allowed in namespace"
|
||||
}
|
||||
require(!name.contains(' ')) {
|
||||
require(name.none { it.isWhitespace() }) {
|
||||
"' ' is not allowed in id"
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,18 @@
|
||||
package net.mamoe.mirai.console.permission
|
||||
|
||||
import org.junit.jupiter.api.Test
|
||||
import kotlin.test.assertFails
|
||||
|
||||
internal class PermissionsBasicsTest {
|
||||
@Test
|
||||
fun testInvalidPermissionId() {
|
||||
assertFails { PermissionId("space namespace", "name") }
|
||||
assertFails { PermissionId("namespace", "space name") }
|
||||
// assertFails { PermissionId("", "name") }
|
||||
// assertFails { PermissionId("namespace", "") }
|
||||
assertFails { PermissionId("namespace:name", "name") }
|
||||
assertFails { PermissionId("namespace", "namespace:name") }
|
||||
}
|
||||
|
||||
@Test
|
||||
fun parentsWithSelfSequence() {
|
||||
|
@ -1,7 +1,7 @@
|
||||
plugins {
|
||||
kotlin("jvm") version "1.4.0"
|
||||
kotlin("plugin.serialization") version "1.4.0"
|
||||
kotlin("kapt") version "1.4.0"
|
||||
kotlin("jvm") version "1.4.10"
|
||||
kotlin("plugin.serialization") version "1.4.10"
|
||||
kotlin("kapt") version "1.4.10"
|
||||
id("com.github.johnrengelman.shadow") version "5.2.0"
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ dependencies {
|
||||
|
||||
testImplementation("net.mamoe:mirai-console:$console")
|
||||
testImplementation("net.mamoe:mirai-core:$core")
|
||||
testImplementation("net.mamoe:mirai-console-pure:$console")
|
||||
testImplementation("net.mamoe:mirai-console-terminal:$console")
|
||||
testImplementation(kotlin("stdlib-jdk8"))
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,8 @@ object MyPluginMain : KotlinPlugin(
|
||||
override fun onEnable() {
|
||||
super.onEnable()
|
||||
PermissionService.INSTANCE.register(permissionId("dvs"), "ok")
|
||||
PermissionService.INSTANCE.register(permissionId("perm with space"), "error")
|
||||
PermissionId("Namespace with space", "Name with space")
|
||||
}
|
||||
|
||||
fun test() {
|
||||
|
@ -85,7 +85,7 @@ class ContextualParametersChecker : DeclarationChecker {
|
||||
fun checkPermissionNamespace(inspectionTarget: PsiElement, value: String): Diagnostic? {
|
||||
return when {
|
||||
value.isBlank() -> ILLEGAL_PERMISSION_NAMESPACE.on(inspectionTarget, value, "权限命名空间不能为空")
|
||||
value.any { it.isWhitespace() } -> ILLEGAL_PERMISSION_NAMESPACE.on(inspectionTarget, value, "暂时不允许权限命名空间中存在空格")
|
||||
value.any { it.isWhitespace() } -> ILLEGAL_PERMISSION_NAMESPACE.on(inspectionTarget, value, "不允许权限命名空间中存在空格")
|
||||
value.contains(':') -> ILLEGAL_PERMISSION_NAMESPACE.on(inspectionTarget, value, "权限命名空间不允许包含 ':'")
|
||||
else -> null
|
||||
}
|
||||
@ -94,7 +94,7 @@ class ContextualParametersChecker : DeclarationChecker {
|
||||
fun checkPermissionName(inspectionTarget: PsiElement, value: String): Diagnostic? {
|
||||
return when {
|
||||
value.isBlank() -> ILLEGAL_PERMISSION_NAME.on(inspectionTarget, value, "权限名称不能为空")
|
||||
value.any { it.isWhitespace() } -> ILLEGAL_PERMISSION_NAME.on(inspectionTarget, value, "暂时不允许权限名称中存在空格")
|
||||
value.any { it.isWhitespace() } -> ILLEGAL_PERMISSION_NAME.on(inspectionTarget, value, "不允许权限名称中存在空格")
|
||||
value.contains(':') -> ILLEGAL_PERMISSION_NAME.on(inspectionTarget, value, "权限名称不允许包含 ':'")
|
||||
else -> null
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user