@@ -3584,22 +3584,28 @@ htmlFixLinks(tree_t *doc, // I - Top node
35843584 progress_error (HD_ERROR_NONE, " DEBUG: Updating links in document." );
35853585 }
35863586
3587+ DEBUG_printf ((" htmlFixLinks: base=\" %s\"\n " , (char *)base));
3588+
35873589 while (tree)
35883590 {
35893591 if (tree->markup == MARKUP_A && base && base[0 ] &&
35903592 (href = htmlGetVariable (tree, (uchar *)" HREF" )) != NULL )
35913593 {
35923594 // Check if the link needs to be localized...
3593- if (href[ 0 ] != ' # ' && file_method ((char *)href) == NULL &&
3594- file_method (( char *)base) != NULL &&
3595- htmlFindFile (doc, (uchar *) file_basename ((char *)href) ) == NULL )
3595+ DEBUG_printf (( " htmlFixLinks: href= \" %s \" , file_method (href)= \" %s \" , file_method(base)= \" %s \"\\ n " , ( char *)href, file_method ((char *)href), file_method (( char *)base)));
3596+
3597+ if (href[ 0 ] != ' # ' && file_method ((char *)href) == NULL )
35963598 {
35973599 // Yes, localize it...
3600+ DEBUG_puts (" htmlFixLinks: Localizing" );
3601+
35983602 if (href[0 ] == ' /' )
35993603 {
36003604 // Absolute URL, just copy scheme, server, etc.
36013605 char *ptr; // Pointer into URL...
36023606
3607+ DEBUG_puts (" htmlFixLinks: Absolute" );
3608+
36033609 strlcpy (full_href, (char *)base, sizeof (full_href));
36043610
36053611 if (href[1 ] == ' /' )
@@ -3608,8 +3614,7 @@ htmlFixLinks(tree_t *doc, // I - Top node
36083614 if ((ptr = strstr (full_href, " //" )) != NULL )
36093615 *ptr =' \0 ' ;
36103616 }
3611- else if ((ptr = strstr (full_href, " //" )) != NULL &&
3612- (ptr = strchr (ptr + 2 , ' /' )) != NULL )
3617+ else if ((ptr = strstr (full_href, " //" )) != NULL && (ptr = strchr (ptr + 2 , ' /' )) != NULL )
36133618 *ptr =' \0 ' ;
36143619
36153620 strlcat (full_href, (char *)href, sizeof (full_href));
@@ -3618,12 +3623,35 @@ htmlFixLinks(tree_t *doc, // I - Top node
36183623 {
36193624 // Relative URL of the form "./foo/bar", append href sans
36203625 // "./" to base to form full href...
3626+ DEBUG_puts (" htmlFixLinks: Current directory" );
3627+
36213628 snprintf (full_href, sizeof (full_href), " %s/%s" , base, href + 2 );
36223629 }
3630+ else if (!strncmp ((char *)href, " ../" , 3 ))
3631+ {
3632+ // Relative URL of the form "../foo/bar", append href sans
3633+ // "../" to parent to form full href...
3634+ char parent[1024 ], *pptr; // Parent directory
3635+
3636+ strlcpy (parent, (char *)base, sizeof (parent));
3637+ if ((pptr = strrchr (parent, ' /' )) != NULL )
3638+ pptr[1 ] = ' \0 ' ;
3639+ else
3640+ parent[0 ] = ' \0 ' ;
3641+
3642+ DEBUG_printf ((" htmlFixLinks: Subdirectory, parent=\" %s\"\n " , parent));
3643+
3644+ snprintf (full_href, sizeof (full_href), " %s%s" , parent, href + 3 );
3645+ }
36233646 else
36243647 {
36253648 // Relative URL, append href to base to form full href...
3626- snprintf (full_href, sizeof (full_href), " %s/%s" , base, href);
3649+ DEBUG_puts (" htmlFixLinks: Relative" );
3650+
3651+ if (strcmp ((char *)base, " ." ))
3652+ snprintf (full_href, sizeof (full_href), " %s/%s" , (char *)base, (char *)href);
3653+ else
3654+ strlcpy (full_href, (char *)href, sizeof (full_href));
36273655 }
36283656
36293657 if (show_debug)
0 commit comments