Changeset 19637 in josm for trunk/test


Ignore:
Timestamp:
2026-10-06T08:57:52+02:00 (8 days ago)
Author:
stoecker
Message:

detect the UTF-8 filename issue in non-UTF contexts, patch by wangi, fix #24940

Location:
trunk/test/unit/org/openstreetmap/josm
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/unit/org/openstreetmap/josm/tools/bugreport/ReportedExceptionTest.java

    r17275 r19637  
    33
    44import static org.junit.jupiter.api.Assertions.assertEquals;
     5import static org.junit.jupiter.api.Assertions.assertFalse;
     6import static org.junit.jupiter.api.Assertions.assertTrue;
    57
     8import java.nio.file.InvalidPathException;
    69import java.util.Arrays;
    710
    … …  
    6265
    6366    /**
     67     * Tests {@link ReportedException#isUnmappableFileName()}: a file name which the character set used for file names
     68     * cannot represent is recognised, also as the cause of another exception, but only if that character set is not
     69     * UTF-8 - otherwise the locale is not to blame. See #14596.
     70     */
     71    @Test
     72    void testIsUnmappableFileName() {
     73        // the exception sun.nio.fs.UnixPath throws for "Capture d'écran.png" when the locale is C or not installed
     74        InvalidPathException unmappable = new InvalidPathException("/home/user/Capture d'\u00e9cran.png",
     75                "Malformed input or input contains unmappable characters");
     76        String jnuEncoding = System.getProperty("sun.jnu.encoding");
     77        try {
     78            System.setProperty("sun.jnu.encoding", "ANSI_X3.4-1968");
     79            assertTrue(new ReportedException(unmappable).isUnmappableFileName());
     80            assertTrue(new ReportedException(new IllegalStateException(unmappable)).isUnmappableFileName());
     81            assertFalse(new ReportedException(new InvalidPathException("a\0b", "Nul character not allowed")).isUnmappableFileName());
     82            assertFalse(new ReportedException(new IllegalStateException()).isUnmappableFileName());
     83
     84            System.setProperty("sun.jnu.encoding", "UTF-8");
     85            assertFalse(new ReportedException(unmappable).isUnmappableFileName());
     86        } finally {
     87            System.setProperty("sun.jnu.encoding", jnuEncoding);
     88        }
     89    }
     90
     91    /**
    6492     * Tests that {@link ReportedException#isSame(ReportedException)} works as expected.
    6593     */
Note: See TracChangeset for help on using the changeset viewer.