Uploaded image for project: 'OpenMRS Core'
  1. OpenMRS Core
  2. TRUNK-4238

OpenmrsUtil.storeProperties should escape backslashes

    XMLWordPrintable

    Details

    • Complexity:
      Low

      Description

      We have custom implementations of writing out Properties to a File or OutputStream, and these do not correctly escape backslashes.

      We originally wrote these custom implementation long ago, prior to using Java 6. Java 6 has native support for what we were trying to do (store and load properties files as UTF-8) so we should just git rid of our custom implementation, and use the underlying Java one.

      Here is a failing unit test comparing our output to the output of the native Java method:

          @Test
          public void storeProperties_shouldEscapeSlashes() throws Exception {
              Charset utf8 = Charset.forName("UTF-8");
              String expectedProperty = "blacklistRegex";
              String expectedValue = "[^\\p{InBasicLatin}\\p{InLatin1Supplement}]";
              Properties properties = new Properties();
              properties.setProperty(expectedProperty, expectedValue);
      
              ByteArrayOutputStream actual = new ByteArrayOutputStream();
              ByteArrayOutputStream expected = new ByteArrayOutputStream();
      
              // our utility method incorrectly writes:
              //     blacklistRegex=[^\p{InBasicLatin}\p{InLatin1Supplement}]
              OpenmrsUtil.storeProperties(properties, actual, null);
      
              // java's underlying implementation correctly writes:
              //     blacklistRegex=[^\\p{InBasicLatin}\\p{InLatin1Supplement}]
              // this method didn't exist in Java 5, which is why we wrote a utility method in the first place, so we should
              // just get rid of our own implementation, and use the underlying java one
              properties.store(new OutputStreamWriter(expected, utf8), null);
      
              assertThat(actual.toByteArray(), is(expected.toByteArray()));
          }
      

        Gliffy Diagrams

          Attachments

            Issue Links

              Activity

                People

                Assignee:
                pmuchowski PaweĊ‚ Muchowski
                Reporter:
                darius Darius Jazayeri
                Votes:
                0 Vote for this issue
                Watchers:
                8 Start watching this issue

                  Dates

                  Created:
                  Updated:
                  Resolved:

                    Time Tracking

                    Estimated:
                    Original Estimate - Not Specified
                    Not Specified
                    Remaining:
                    Remaining Estimate - 0 minutes
                    0m
                    Logged:
                    Time Spent - 1 day, 4 hours, 10 minutes
                    1d 4h 10m