https://bz.apache.org/bugzilla/show_bug.cgi?id=65638

            Bug ID: 65638
           Summary: [PATCH] Remove escaping of ampersand from headers and
                    footers created by Excel
           Product: POI
           Version: 5.0.x-dev
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P2
         Component: XSSF
          Assignee: [email protected]
          Reporter: [email protected]
  Target Milestone: ---

In Excel headers and footers (both .xls and .xlsx) an ampersand "&" is used as
the start of formatting fields.  If a user wants to enter an ampersand as text
in a header, they need to "escape" it as "&&".  In order words to display "&"
in a header you need to enter "&&".  This patch removes that escaping when
removing other formatting via another regex in
org.apache.poi.hssf.usermodel.HeaderFooter.stripFields()
  text = text.replaceAll("&&", "&");

Also, in the existing code the string which defines the regex has a backslash
before the ampersand.
  text = text.replaceAll("\\&\\d+", "");
The ampersand in the regex does not need to be escaped, it can be written as:
  text = text.replaceAll("&\\d+", "");
The backslash has been removed in 4 lines to make the new line consistent with
the existing ones.

The patch contains a .xls and a .xlsx file produced in Excel with a header that
displays as "one & two &&" and is used for unit testing.

Two existing unit tests have also been corrected which were previously
confirming the incorrect behaviour.  These appear to be tests generated by
examining the code rather than seeing what Excel generates.

-- 
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to