diff --git a/jvm/src/test/scala/scala/xml/XMLTest.scala b/jvm/src/test/scala/scala/xml/XMLTest.scala
index efdb8165a..0ca1ff1ce 100644
--- a/jvm/src/test/scala/scala/xml/XMLTest.scala
+++ b/jvm/src/test/scala/scala/xml/XMLTest.scala
@@ -315,7 +315,10 @@ class XMLTestJVM {
     val inputStream = new java.io.ByteArrayInputStream(outputStream.toByteArray)
     val streamReader = new java.io.InputStreamReader(inputStream, XML.encoding)
 
-    assertEquals(xml.toString, XML.load(streamReader).toString)
+    def unescapeQuotes(str: String) = 
+      """.r.replaceFirstIn(str, "\"")
+    val xmlFixed = unescapeQuotes(xml.toString)
+    assertEquals(xmlFixed, XML.load(streamReader).toString)
   }
 
   @UnitTest
diff --git a/shared/src/main/scala/scala/xml/Text.scala b/shared/src/main/scala/scala/xml/Text.scala
index 8e2ee498f..caa7fa294 100644
--- a/shared/src/main/scala/scala/xml/Text.scala
+++ b/shared/src/main/scala/scala/xml/Text.scala
@@ -23,7 +23,7 @@ class Text(data: String) extends Atom[String](data) {
    *  specification.
    */
   override def buildString(sb: StringBuilder): StringBuilder =
-    Utility.escape(data, sb)
+    Utility.escapeText(data, sb)
 }
 
 /**
diff --git a/shared/src/main/scala/scala/xml/Utility.scala b/shared/src/main/scala/scala/xml/Utility.scala
index 776da5a7a..43776af94 100755
--- a/shared/src/main/scala/scala/xml/Utility.scala
+++ b/shared/src/main/scala/scala/xml/Utility.scala
@@ -127,6 +127,20 @@ object Utility extends AnyRef with parsing.TokenTests {
     }
   }
 
+  /**
+   * Appends escaped string to `s`, but not ".
+   */
+  final def escapeText(text: String, s: StringBuilder): StringBuilder = {
+    val escTextMap = escMap - '"' // Remove quotes from escMap
+    text.iterator.foldLeft(s) { (s, c) =>
+      escTextMap.get(c) match {
+        case Some(str)                             => s ++= str
+        case _ if c >= ' ' || "\n\r\t".contains(c) => s += c
+        case _ => s // noop
+      }
+    }
+  }
+
   /**
    * Appends unescaped string to `s`, `amp` becomes `&`,
    * `lt` becomes `<` etc..
diff --git a/shared/src/test/scala/scala/xml/XMLTest.scala b/shared/src/test/scala/scala/xml/XMLTest.scala
index a9644ca6d..1e0a304c7 100644
--- a/shared/src/test/scala/scala/xml/XMLTest.scala
+++ b/shared/src/test/scala/scala/xml/XMLTest.scala
@@ -307,10 +307,10 @@ class XMLTest {
   @UnitTest
   def escape =
     assertEquals("""
- "Come, come again, whoever you are, come!
+ "Come, come again, whoever you are, come!
 Heathen, fire worshipper or idolatrous, come!
 Come even if you broke your penitence a hundred times,
-Ours is the portal of hope, come as you are."
+Ours is the portal of hope, come as you are."
                               Mevlana Celaleddin Rumi""", <![CDATA[
  "Come, come again, whoever you are, come!
 Heathen, fire worshipper or idolatrous, come!
@@ -473,6 +473,22 @@ Ours is the portal of hope, come as you are."
     assertHonorsIterableContract(<a a="" y={ null: String }/>.attributes)
   }
 
+  @UnitTest
+  def t5645: Unit = {
+
+    val bar = "baz"
+    val script = <script type="text/javascript">
+      foo("{bar}");
+    </script>
+
+    val expected =
+      """|<script type="text/javascript">
+         |      foo("baz");
+         |    </script>""".stripMargin
+
+    assertEquals(expected, script.toString)
+  }
+
   @UnitTest
   def t5843: Unit = {
     val foo = scala.xml.Attribute(null, "foo", "1", scala.xml.Null)