Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ ThisBuild / libraryDependencies ++= Seq(
scalactic,
scalatest
)
ThisBuild / libraryDependencies ++= specs2XmlDeps(scalaVersion.value)

ThisBuild / scalacOptions ++= Seq("-deprecation")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import scala.language.postfixOps
import collection.immutable.StringOps
import collection.mutable.ListBuffer
import scala.xml.{Group, Node, Text, NodeSeq, Elem => XmlElem, TopScope, XML}
import scala.xml.parsing.XhtmlParser
import util.parsing.combinator.{Parsers, RegexParsers}

/**
Expand Down
54 changes: 8 additions & 46 deletions core/util/src/main/scala/net/liftweb/util/HtmlParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package util

import net.liftweb.common._
import scala.xml._
import parsing._
import java.io._

import nu.validator.htmlparser._
Expand Down Expand Up @@ -344,53 +343,16 @@ trait Html5Parser {
hp.setContentNonXmlCharPolicy(common.XmlViolationPolicy.ALLOW)
hp.setContentSpacePolicy(common.XmlViolationPolicy.FATAL)
hp.setNamePolicy(common.XmlViolationPolicy.ALLOW)
val saxer = new NoBindingFactoryAdapter {
/*
override def createNode (pre: String, label: String, attrs: MetaData, scope: NamespaceBinding, children: List[Node]) : Elem = {
if (pre == "lift" && label == "head") {
super.createNode(null, label, attrs, scope, children)
} else {
super.createNode(pre, label, attrs, scope, children)
}
}*/

override def captureText(): Unit = {
if (capture) {
val text = buffer.toString()
if (text.length() > 0) {
hStack = hStack.prepended(createText(text))
}
}
buffer.setLength(0)
}

// Override endDocument to handle empty hStack case in Scala 3
// Scala 3's List.last throws "None.get" error on empty lists
override def endDocument(): Unit = {
if (hStack.nonEmpty) {
epilogue = hStack.init.reverse
hStack = hStack.last :: Nil
}
}
}

saxer.scopeStack = saxer.scopeStack.prepended(TopScope)
hp.setContentHandler(saxer)
val is = new InputSource(in)
is.setEncoding("UTF-8")
hp.parse(is)

saxer.scopeStack = saxer.scopeStack.drop(1)

in.close()
saxer.rootElem match {
case null => Empty
case e: Elem =>
AutoInsertedBody.unapply(e) match {
case Some(x) => Full(x)
case _ => Full(e)
}
case _ => Empty
try {
val elem = scala.xml.XML.withXMLReader(hp).load(is)
AutoInsertedBody.unapply(elem) match {
case Some(x) => Full(x)
case _ => Full(elem)
}
} finally {
in.close()
}
}.flatMap(a => a)
}
Expand Down
Loading
Loading