@@ -517,10 +517,84 @@ public void testBogusFile() throws IOException {
517517
518518 @ Test
519519 public void testFileWithPunctuationToURL () throws MalformedURLException {
520+ // What matters is that all punctuation survives the fileToURL → urlToString round-trip
521+ // so FFmpeg receives the correct literal path. The intermediate URL encoding may vary.
520522 Assume .assumeTrue (File .separator .equals ("/" ));
521523 final File file = new File ("/someDir/;:&=+@[]?/name.txt" );
522524 final URL url = FFAudioFileReader .fileToURL (file );
523- assertEquals ("file:/someDir/;:&=+@[]?/name.txt" , url .toString ());
525+ final String s = FFAudioFileReader .urlToString (url );
526+ assertTrue (
527+ "Punctuation must survive round-trip: " + s ,
528+ s .contains ("/someDir/" )
529+ && s .contains (";" )
530+ && s .contains ("&" )
531+ && s .contains ("+" )
532+ && s .contains ("[" )
533+ && s .contains ("]" )
534+ && s .endsWith ("name.txt" ));
535+ }
536+
537+ @ Test
538+ public void testFileWithPercentSignToURL () throws MalformedURLException {
539+ // A literal % in a file path must survive the fileToURL → urlToString round-trip intact.
540+ Assume .assumeTrue (File .separator .equals ("/" ));
541+ final File file = new File ("/someDir/50%off/name.ogg" );
542+ final URL url = FFAudioFileReader .fileToURL (file );
543+ final String s = FFAudioFileReader .urlToString (url );
544+ assertTrue ("Round-tripped path must contain literal percent sign: " + s , s .contains ("50%off" ));
545+ }
546+
547+ @ Test
548+ public void testGetAudioFileFormatFileWithPercentSign ()
549+ throws IOException , UnsupportedAudioFileException {
550+ final String filename = "test.ogg" ;
551+ final File file = File .createTempFile ("test50%off" , filename );
552+ extractFile (filename , file );
553+ try {
554+ final AudioFileFormat fileFormat = new FFAudioFileReader ().getAudioFileFormat (file );
555+ assertEquals ("ogg" , fileFormat .getType ().getExtension ());
556+ assertEquals (2 , fileFormat .getFormat ().getChannels ());
557+ } finally {
558+ file .delete ();
559+ }
560+ }
561+
562+ @ Test
563+ public void testGetAudioFileFormatURLWithPercentSign ()
564+ throws IOException , UnsupportedAudioFileException {
565+ // file.toURI().toURL() keeps % encoded as %25; urlToString() must decode it for FFmpeg.
566+ final String filename = "test.ogg" ;
567+ final File file = File .createTempFile ("test50%off" , filename );
568+ extractFile (filename , file );
569+ try {
570+ final AudioFileFormat fileFormat =
571+ new FFAudioFileReader ().getAudioFileFormat (file .toURI ().toURL ());
572+ assertEquals ("ogg" , fileFormat .getType ().getExtension ());
573+ assertEquals (2 , fileFormat .getFormat ().getChannels ());
574+ } finally {
575+ file .delete ();
576+ }
577+ }
578+
579+ @ Test
580+ public void testGetAudioInputStreamFileWithPercentSign ()
581+ throws IOException , UnsupportedAudioFileException {
582+ final String filename = "test.ogg" ;
583+ final File file = File .createTempFile ("test50%off" , filename );
584+ extractFile (filename , file );
585+ try {
586+ final AudioInputStream stream = new FFAudioFileReader ().getAudioInputStream (file );
587+ try {
588+ final byte [] buf = new byte [1024 ];
589+ assertTrue (
590+ "Expected to read audio bytes from file with percent sign in name" ,
591+ stream .read (buf ) > 0 );
592+ } finally {
593+ stream .close ();
594+ }
595+ } finally {
596+ file .delete ();
597+ }
524598 }
525599
526600 @ Test
0 commit comments