mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Fixed exception Invalid html: tag <html> inserted automatically and shouldn't be used, text: <html>I agree to ...
Stacktrace:
at com.intellij.ui.dsl.builder.components.DslLabel.setText(DslLabel.kt:122)
at com.intellij.diagnostic.PrivacyNotice$privacyPolicy$2.set(PrivacyNotice.kt:21)
at com.intellij.diagnostic.PrivacyNotice.setPrivacyPolicy(PrivacyNotice.kt:21)
GitOrigin-RevId: ebb44f6abb6234ca8ec9cb77ef05a29ee6252574
This commit is contained in:
committed by
intellij-monorepo-bot
parent
7d26d08728
commit
a644da8b92
@@ -4,6 +4,7 @@ package com.intellij.ui.dsl.builder
|
||||
import com.intellij.ide.BrowserUtil
|
||||
import com.intellij.ide.ui.UINumericRange
|
||||
import com.intellij.ui.SimpleListCellRenderer
|
||||
import org.jetbrains.annotations.Nls
|
||||
import javax.swing.JComponent
|
||||
import javax.swing.JLabel
|
||||
import javax.swing.JList
|
||||
@@ -117,3 +118,19 @@ fun <T> listCellRenderer(renderer: SimpleListCellRenderer<T>.(T) -> Unit): Simpl
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Kotlin UI DSL doesn't allow to use some tags like <html> so all resource strings should be cleared up manually. Sometimes strings are
|
||||
* received from outside, in such cases this method can be useful
|
||||
*
|
||||
* Example: `cleanupHtml("<html>Some string</html>")` returns `"Some string"`
|
||||
*/
|
||||
fun cleanupHtml(@Nls s: String): @Nls String {
|
||||
val regex = Regex("\\s*<html>(?<body>.*)</html>\\s*", RegexOption.IGNORE_CASE)
|
||||
val result = regex.matchEntire(s)
|
||||
if (result == null) {
|
||||
return s
|
||||
}
|
||||
@Suppress("HardCodedStringLiteral")
|
||||
return result.groups["body"]!!.value
|
||||
}
|
||||
|
||||
@@ -3,7 +3,9 @@ package com.intellij.diagnostic
|
||||
|
||||
import com.intellij.openapi.util.NlsContexts
|
||||
import com.intellij.ui.dsl.builder.CollapsibleRow
|
||||
import com.intellij.ui.dsl.builder.cleanupHtml
|
||||
import com.intellij.ui.dsl.builder.panel
|
||||
import org.jetbrains.annotations.Nls
|
||||
import javax.swing.JEditorPane
|
||||
|
||||
class PrivacyNotice(@NlsContexts.Label label: String, @NlsContexts.Label privacyPolicy: String) {
|
||||
@@ -18,7 +20,10 @@ class PrivacyNotice(@NlsContexts.Label label: String, @NlsContexts.Label privacy
|
||||
}
|
||||
|
||||
var expanded: Boolean by collapsibleRow::expanded
|
||||
var privacyPolicy: String by privacyPolicyPane::text
|
||||
|
||||
fun setPrivacyPolicy(@Nls text: String) {
|
||||
privacyPolicyPane.text = cleanupHtml(text)
|
||||
}
|
||||
|
||||
private lateinit var collapsibleRow: CollapsibleRow
|
||||
private lateinit var privacyPolicyPane: JEditorPane
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.ui.dsl.builder
|
||||
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class UtilsTest {
|
||||
|
||||
@Test
|
||||
fun testCleanupHtml() {
|
||||
val testData = mapOf(
|
||||
"Hello" to "Hello",
|
||||
" Hello " to " Hello ",
|
||||
"<html>Hello</html>" to "Hello",
|
||||
" <html> Hello </html> " to " Hello ",
|
||||
"<html>Hello" to "<html>Hello",
|
||||
)
|
||||
|
||||
for ((original, expected) in testData) {
|
||||
assertEquals(expected, cleanupHtml(original))
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user