Skip to content

Commit

Permalink
Merge pull request nasa#554 from nasa/issue-553-fpp-to-xml
Browse files Browse the repository at this point in the history
[fpp-to-xml] Escape special characters in comments
  • Loading branch information
bocchino authored Jan 6, 2025
2 parents 0530a61 + cb09cf7 commit 8245f4f
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ object AnnotationXmlWriter extends LineUtils {

/** Write a multiline comment */
def multilineComment[T](a: Ast.Annotated[T]): List[Line] = {
(a._1 ++ a._3).map(line) match {
(a._1 ++ a._3).map(line compose XmlTags.escaped) match {
case Nil => Nil
case ls => {
val tags = XmlTags.tags("comment")
Expand All @@ -19,7 +19,7 @@ object AnnotationXmlWriter extends LineUtils {

/** Write a single-line comment */
def singleLineComment[T](a: Ast.Annotated[T]): Option[(String, String)] = {
val s = (a._1 ++ a._3).mkString(" ")
val s = (a._1 ++ a._3).map(XmlTags.escaped).mkString(" ")
if (s.length > 0) Some(("comment", s)) else None
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>

<!-- =====================================================================
ArraySpecialCommentArrayAi.xml
Generated by fpp-to-xml
====================================================================== -->
<array name="ArraySpecialComment">
<comment>
An array with special characters in XML comments
&amp;&apos;&lt;&gt;&quot;
&amp;&apos;&lt;&gt;&quot;
</comment>
<type>U32</type>
<size>3</size>
<format>%u</format>
<default>
<value>0</value>
<value>0</value>
<value>0</value>
</default>
</array>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@ An array with special characters in XML comments
@ &'<>"
array ArraySpecialComment = [3] U32 @< &'<>"
Empty file.
6 changes: 6 additions & 0 deletions compiler/tools/fpp-to-xml/test/array/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ array_ok()
diff_xml ArrayOK1Array ArrayOK2Array ArrayOK3Array ArrayOK4Array ArrayOK5Array
}

array_special_comment()
{
run_test "-p $PWD" array_special_comment && \
diff_xml ArraySpecialCommentArray
}

array_struct()
{
run_test "-p $PWD" array_struct && \
Expand Down
1 change: 1 addition & 0 deletions compiler/tools/fpp-to-xml/test/array/tests.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
tests="
array_enum
array_ok
array_special_comment
array_struct
built_in_type
array_struct_member_array
Expand Down
7 changes: 7 additions & 0 deletions compiler/tools/fpp-to-xml/test/array/update-ref.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ array_ok()
move_xml ArrayOK1Array ArrayOK2Array ArrayOK3Array ArrayOK4Array ArrayOK5Array
}

array_special_comment()
{
update "-p $PWD" array_special_comment
move_xml ArraySpecialCommentArray
}

array_struct()
{
update "-p $PWD" array_struct
Expand All @@ -25,6 +31,7 @@ array_struct_member_array()
update "-p $PWD" array_struct_member_array
move_xml ArrayStructMemberArraySerializable ArrayStructMemberArrayArray
}

built_in_type()
{
update "-p $PWD" built_in_type
Expand Down
4 changes: 0 additions & 4 deletions compiler/tools/fpp-to-xml/test/scripts/check-xml.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,6 @@
# ----------------------------------------------------------------------
# Compile ref XML files, to check them for validity
# ----------------------------------------------------------------------
# 1. Compile from XML to C++
# 2. Compile to C++ where feasible. Skip it if the F Prime dependencies
# are too complicated.
# ----------------------------------------------------------------------

pwd=$PWD

Expand Down

0 comments on commit 8245f4f

Please sign in to comment.