@@ -1354,10 +1354,9 @@ private void executeRefreshIfNeeded() throws IOException {
13541354 final double time ;
13551355 final URL url ;
13561356
1357- int index = StringUtils .indexOfAnyBut (refreshString , "0123456789" );
1358- final boolean timeOnly = index == -1 ;
1357+ final int index = StringUtils .indexOfAnyBut (refreshString , "0123456789." );
13591358
1360- if (timeOnly ) {
1359+ if (index == - 1 ) {
13611360 // Format: <meta http-equiv='refresh' content='10'>
13621361 try {
13631362 time = Double .parseDouble (refreshString );
@@ -1373,43 +1372,56 @@ private void executeRefreshIfNeeded() throws IOException {
13731372 else {
13741373 // Format: <meta http-equiv='refresh' content='10;url=http://www.blah.com'>
13751374 try {
1376- time = Double .parseDouble (refreshString .substring (0 , index ). trim () );
1375+ time = Double .parseDouble (refreshString .substring (0 , index ));
13771376 }
13781377 catch (final NumberFormatException e ) {
13791378 if (LOG .isErrorEnabled ()) {
13801379 LOG .error ("Malformed refresh string (no valid number before ';') " + refreshString , e );
13811380 }
13821381 return ;
13831382 }
1384- index = refreshString .toLowerCase (Locale .ROOT ).indexOf ("url=" , index );
1385- if (index == -1 ) {
1386- if (LOG .isErrorEnabled ()) {
1387- LOG .error ("Malformed refresh string (found ';' but no 'url='): " + refreshString );
1388- }
1389- return ;
1390- }
1391- final StringBuilder builder = new StringBuilder (refreshString .substring (index + 4 ));
1392- if (StringUtils .isBlank (builder .toString ())) {
1393- //content='10; URL=' is treated as content='10'
1394- url = getUrl ();
1395- }
1396- else {
1397- if (builder .charAt (0 ) == '"' || builder .charAt (0 ) == 0x27 ) {
1398- builder .deleteCharAt (0 );
1399- }
1400- if (builder .charAt (builder .length () - 1 ) == '"' || builder .charAt (builder .length () - 1 ) == 0x27 ) {
1401- builder .deleteCharAt (builder .length () - 1 );
1383+
1384+ String urlPart = refreshString .substring (index );
1385+ final char separator = urlPart .charAt (0 );
1386+ if (";, \r \n \t " .indexOf (separator ) >= 0 ) {
1387+ urlPart = StringUtils .stripStart (urlPart , ";, \r \n \t " );
1388+ if (urlPart .toLowerCase (Locale .ROOT ).startsWith ("url" )) {
1389+ urlPart = urlPart .substring (3 );
1390+ urlPart = urlPart .trim ();
1391+
1392+ if (urlPart .toLowerCase ().startsWith ("=" )) {
1393+ urlPart = urlPart .substring (1 );
1394+ urlPart = urlPart .trim ();
1395+ }
14021396 }
1403- final String urlString = builder .toString ();
1404- try {
1405- url = getFullyQualifiedUrl (urlString );
1397+
1398+ if (StringUtils .isBlank (urlPart )) {
1399+ //content='10; URL=' is treated as content='10'
1400+ url = getUrl ();
14061401 }
1407- catch (final MalformedURLException e ) {
1408- if (LOG .isErrorEnabled ()) {
1409- LOG .error ("Malformed URL in refresh string: " + refreshString , e );
1402+ else {
1403+ if (urlPart .charAt (0 ) == '"' || urlPart .charAt (0 ) == 0x27 ) {
1404+ urlPart = urlPart .substring (1 );
1405+ }
1406+ if (urlPart .charAt (urlPart .length () - 1 ) == '"' || urlPart .charAt (urlPart .length () - 1 ) == 0x27 ) {
1407+ urlPart = urlPart .substring (0 , urlPart .length () - 1 );
1408+ }
1409+ try {
1410+ url = getFullyQualifiedUrl (urlPart );
14101411 }
1411- throw e ;
1412+ catch (final MalformedURLException e ) {
1413+ if (LOG .isErrorEnabled ()) {
1414+ LOG .error ("Malformed URL in refresh string: " + refreshString , e );
1415+ }
1416+ return ;
1417+ }
1418+ }
1419+ }
1420+ else {
1421+ if (LOG .isErrorEnabled ()) {
1422+ LOG .error ("Malformed refresh string (separator after time missing): " + refreshString );
14121423 }
1424+ return ;
14131425 }
14141426 }
14151427
0 commit comments