Skip to content

Commit

Permalink
Fix issue osdn#46082: Fix incorrect links to files with # in filename…
Browse files Browse the repository at this point in the history
… in folder comparison report (2)
  • Loading branch information
sdottaka committed May 11, 2024
1 parent d628c2c commit e52f9a5
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
5 changes: 1 addition & 4 deletions Src/DirCmpReport.cpp
Expand Up @@ -514,9 +514,6 @@ void DirCmpReport::GenerateXmlHtmlContent(bool xml)
if (!xml && m_bIncludeFileCmpReport && m_pFileCmpReport != nullptr)
(*m_pFileCmpReport.get())(REPORT_TYPE_SIMPLEHTML, m_pList.get(), currRow, sDestDir, sLinkPath);

strutils::replace(sLinkPath, _T("%"), _T("%25"));
strutils::replace(sLinkPath, _T("#"), _T("%23"));

String rowEl = _T("tr");
if (xml)
{
Expand Down Expand Up @@ -553,7 +550,7 @@ void DirCmpReport::GenerateXmlHtmlContent(bool xml)
WriteString(_T("<a href=\""));
WriteString(sRelDestDir);
WriteString(_T("/"));
WriteString(sLinkPath);
WriteString(paths::urlEncodeFileName(sLinkPath));
WriteString(_T("\">"));
WriteStringEntityAware(m_pList->GetItemText(currRow, currCol));
WriteString(_T("</a>"));
Expand Down
2 changes: 1 addition & 1 deletion Src/ImgMergeFrm.cpp
Expand Up @@ -2305,7 +2305,7 @@ bool CImgMergeFrame::GenerateReport(const String& sFileName, bool allPages) cons
for (int pane = 0; pane < m_pImgMergeWindow->GetPaneCount(); ++pane)
file.WriteString(
strutils::format(_T("<td><div class=\"img\"><img src=\"%s\" alt=\"%s\"></div></td>\n"),
filenames[pane], filenames[pane]));
paths::urlEncodeFileName(filenames[pane]), filenames[pane]));
file.WriteString(
_T("</tr>\n"));
}
Expand Down
2 changes: 1 addition & 1 deletion Src/WebPageDiffFrm.cpp
Expand Up @@ -1629,7 +1629,7 @@ bool CWebPageDiffFrame::GenerateReport(const String& sFileName, std::function<vo
for (int pane = 0; pane < m_pWebDiffWindow->GetPaneCount(); ++pane)
file.WriteString(
strutils::format(_T("<td><embed type=\"application/pdf\" src=\"%s\" title=\"%s\"></td>\n"),
diffrpt_filename[pane], diffrpt_filename[pane]));
paths::urlEncodeFileName(diffrpt_filename[pane]), diffrpt_filename[pane]));
file.WriteString(
_T("</tr>\n"));
file.WriteString(
Expand Down
8 changes: 8 additions & 0 deletions Src/paths.cpp
Expand Up @@ -769,6 +769,14 @@ String FromURL(const String& url)
return path.data();
}

String urlEncodeFileName(const String& filename)
{
String encoded = filename;
strutils::replace(encoded, _T("%"), _T("%25"));
strutils::replace(encoded, _T("#"), _T("%23"));
return encoded;
}

bool IsDecendant(const String& path, const String& ancestor)
{
return path.length() > ancestor.length() &&
Expand Down
1 change: 1 addition & 0 deletions Src/paths.h
Expand Up @@ -52,6 +52,7 @@ bool IsURL(const String& path);
bool IsURLorCLSID(const String& path);
bool isFileURL(const String& path);
String FromURL(const String& url);
String urlEncodeFileName(const String& filename);
bool IsDecendant(const String& path, const String& ancestor);
inline String AddTrailingSlash(const String& path) { return !EndsWithSlash(path) ? path + _T("\\") : path; }
String ToWindowsPath(const String& path);
Expand Down

0 comments on commit e52f9a5

Please sign in to comment.