mirror of https://github.com/sbt/sbt.git
Handle html entities in XML files
This commit is contained in:
parent
2f0eb1dba8
commit
394f9f2bb6
|
|
@ -0,0 +1,99 @@
|
|||
package coursier.core.compatibility
|
||||
|
||||
object Entities {
|
||||
|
||||
// Generated via https://gist.github.com/alexarchambault/79388ff31ec8cbddf6607b55ab2f6527
|
||||
|
||||
val entities = Vector(
|
||||
(" ", " "),
|
||||
("¡", "¡"),
|
||||
("¢", "¢"),
|
||||
("£", "£"),
|
||||
("¤", "¤"),
|
||||
("¥", "¥"),
|
||||
("¦", "¦"),
|
||||
("§", "§"),
|
||||
("¨", "¨"),
|
||||
("©", "©"),
|
||||
("ª", "ª"),
|
||||
("«", "«"),
|
||||
("¬", "¬"),
|
||||
("­", "­"),
|
||||
("®", "®"),
|
||||
("¯", "¯"),
|
||||
("°", "°"),
|
||||
("±", "±"),
|
||||
("´", "´"),
|
||||
("µ", "µ"),
|
||||
("¶", "¶"),
|
||||
("·", "·"),
|
||||
("¸", "¸"),
|
||||
("º", "º"),
|
||||
("»", "»"),
|
||||
("¿", "¿"),
|
||||
("À", "À"),
|
||||
("Á", "Á"),
|
||||
("Â", "Â"),
|
||||
("Ã", "Ã"),
|
||||
("Ä", "Ä"),
|
||||
("Å", "Å"),
|
||||
("Æ", "Æ"),
|
||||
("Ç", "Ç"),
|
||||
("È", "È"),
|
||||
("É", "É"),
|
||||
("Ê", "Ê"),
|
||||
("Ë", "Ë"),
|
||||
("Ì", "Ì"),
|
||||
("Í", "Í"),
|
||||
("Î", "Î"),
|
||||
("Ï", "Ï"),
|
||||
("Ð", "Ð"),
|
||||
("Ñ", "Ñ"),
|
||||
("Ò", "Ò"),
|
||||
("Ó", "Ó"),
|
||||
("Ô", "Ô"),
|
||||
("Õ", "Õ"),
|
||||
("Ö", "Ö"),
|
||||
("×", "×"),
|
||||
("Ø", "Ø"),
|
||||
("Ù", "Ù"),
|
||||
("Ú", "Ú"),
|
||||
("Û", "Û"),
|
||||
("Ü", "Ü"),
|
||||
("Ý", "Ý"),
|
||||
("Þ", "Þ"),
|
||||
("ß", "ß"),
|
||||
("à", "à"),
|
||||
("á", "á"),
|
||||
("â", "â"),
|
||||
("ã", "ã"),
|
||||
("ä", "ä"),
|
||||
("å", "å"),
|
||||
("æ", "æ"),
|
||||
("ç", "ç"),
|
||||
("è", "è"),
|
||||
("é", "é"),
|
||||
("ê", "ê"),
|
||||
("ë", "ë"),
|
||||
("ì", "ì"),
|
||||
("í", "í"),
|
||||
("î", "î"),
|
||||
("ï", "ï"),
|
||||
("ð", "ð"),
|
||||
("ñ", "ñ"),
|
||||
("ò", "ò"),
|
||||
("ó", "ó"),
|
||||
("ô", "ô"),
|
||||
("õ", "õ"),
|
||||
("ö", "ö"),
|
||||
("÷", "÷"),
|
||||
("ø", "ø"),
|
||||
("ù", "ù"),
|
||||
("ú", "ú"),
|
||||
("û", "û"),
|
||||
("ü", "ü"),
|
||||
("ý", "ý"),
|
||||
("þ", "þ"),
|
||||
("ÿ", "ÿ")
|
||||
)
|
||||
}
|
||||
|
|
@ -2,6 +2,8 @@ package coursier.core
|
|||
|
||||
import coursier.util.Xml
|
||||
|
||||
import java.util.regex.Pattern.quote
|
||||
|
||||
import scala.collection.JavaConverters._
|
||||
import scala.xml.{ Attribute, MetaData, Null }
|
||||
|
||||
|
|
@ -14,11 +16,23 @@ package object compatibility {
|
|||
def letter = c.isLetter
|
||||
}
|
||||
|
||||
private val entityPattern = (quote("&") + "[a-zA-Z]+" + quote(";")).r
|
||||
|
||||
private val utf8Bom = "\ufeff"
|
||||
|
||||
def xmlParse(s: String): Either[String, Xml.Node] = {
|
||||
|
||||
val content =
|
||||
if (entityPattern.findFirstIn(s).isEmpty)
|
||||
s
|
||||
else
|
||||
Entities.entities.foldLeft(s) {
|
||||
case (s0, (target, replacement)) =>
|
||||
s0.replace(target, replacement)
|
||||
}
|
||||
|
||||
def parse =
|
||||
try Right(scala.xml.XML.loadString(s.stripPrefix(utf8Bom)))
|
||||
try Right(scala.xml.XML.loadString(content.stripPrefix(utf8Bom)))
|
||||
catch { case e: Exception => Left(e.toString + Option(e.getMessage).fold("")(" (" + _ + ")")) }
|
||||
|
||||
def fromNode(node: scala.xml.Node): Xml.Node =
|
||||
|
|
|
|||
|
|
@ -0,0 +1 @@
|
|||
org.codehaus.plexus:plexus:1.0.4:compile
|
||||
|
|
@ -616,6 +616,13 @@ object CentralTests extends TestSuite {
|
|||
}
|
||||
}
|
||||
|
||||
'entities - {
|
||||
'odash - resolutionCheck(
|
||||
Module("org.codehaus.plexus", "plexus"),
|
||||
"1.0.4"
|
||||
)
|
||||
}
|
||||
|
||||
'parentBeforeImports - {
|
||||
* - resolutionCheck(
|
||||
Module("org.kie", "kie-api"),
|
||||
|
|
|
|||
Loading…
Reference in New Issue