OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 Eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 * The criterion is that it appear in the "html/templates" folder within our i
nstallation. | 150 * The criterion is that it appear in the "html/templates" folder within our i
nstallation. |
151 * | 151 * |
152 * Warning: This function may fail if the argument is not a "file://" URL. | 152 * Warning: This function may fail if the argument is not a "file://" URL. |
153 * This is occasionally the case in circumstances yet to be characterized. | 153 * This is occasionally the case in circumstances yet to be characterized. |
154 */ | 154 */ |
155 bool IsOurHtmlFile(const std::wstring& url) | 155 bool IsOurHtmlFile(const std::wstring& url) |
156 { | 156 { |
157 // Declared static because the value is derived from an installation directo
ry, which won't change during run-time. | 157 // Declared static because the value is derived from an installation directo
ry, which won't change during run-time. |
158 static auto dir = FileUrl(HtmlFolderPath()); | 158 static auto dir = FileUrl(HtmlFolderPath()); |
159 | 159 |
| 160 dir = EscapeUrl(CanonicalizeUrl(dir)); |
| 161 std::wstring urlCanonicalized = EscapeUrl(CanonicalizeUrl(url)); |
| 162 |
160 DEBUG_GENERAL([&]() -> std::wstring { | 163 DEBUG_GENERAL([&]() -> std::wstring { |
161 std::wstring log = L"InjectABP. Current URL: "; | 164 std::wstring log = L"InjectABP. Current URL: "; |
162 log += url; | 165 log += urlCanonicalized; |
163 log += L", template directory URL: "; | 166 log += L", template directory URL: "; |
164 log += dir; | 167 log += dir; |
165 return log; | 168 return log; |
166 }()); | 169 }()); |
167 | 170 |
168 /* | 171 /* |
169 * The length check here is defensive, in case the document URL is truncated
for some reason. | 172 * The length check here is defensive, in case the document URL is truncated
for some reason. |
170 */ | 173 */ |
171 if (url.length() < 5) | 174 if (urlCanonicalized.length() < 5) |
172 { | 175 { |
173 // We can't match ".html" at the end of the URL if it's too short. | 176 // We can't match ".html" at the end of the URL if it's too short. |
174 return false; | 177 return false; |
175 } | 178 } |
176 auto urlCstr = url.c_str(); | 179 auto urlCstr = urlCanonicalized.c_str(); |
177 // Check the prefix to match our directory | 180 // Check the prefix to match our directory |
178 // Check the suffix to be an HTML file | 181 // Check the suffix to be an HTML file |
| 182 // Compare escaped version and return |
179 return (_wcsnicmp(urlCstr, dir.c_str(), dir.length()) == 0) && | 183 return (_wcsnicmp(urlCstr, dir.c_str(), dir.length()) == 0) && |
180 (_wcsnicmp(urlCstr + url.length() - 5, L".html", 5) == 0); | 184 (_wcsnicmp(urlCstr + url.length() - 5, L".html", 5) == 0); |
181 } | 185 } |
182 } | 186 } |
183 | 187 |
184 void CPluginTab::InjectABP(IWebBrowser2* browser) | 188 void CPluginTab::InjectABP(IWebBrowser2* browser) |
185 { | 189 { |
186 CriticalSection::Lock lock(m_csInject); | 190 CriticalSection::Lock lock(m_csInject); |
187 auto url = GetDocumentUrl(); | 191 auto url = GetDocumentUrl(); |
188 if (!IsOurHtmlFile(url)) | 192 if (!IsOurHtmlFile(url)) |
(...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 LogQueue::LogPluginError(pluginError.GetErrorCode(), pluginError.GetEr
rorId(), pluginError.GetErrorSubid(), pluginError.GetErrorDescription(), true, p
luginError.GetProcessId(), pluginError.GetThreadId()); | 619 LogQueue::LogPluginError(pluginError.GetErrorCode(), pluginError.GetEr
rorId(), pluginError.GetErrorSubid(), pluginError.GetErrorDescription(), true, p
luginError.GetProcessId(), pluginError.GetThreadId()); |
616 } | 620 } |
617 | 621 |
618 // Non-hanging sleep | 622 // Non-hanging sleep |
619 Sleep(50); | 623 Sleep(50); |
620 } | 624 } |
621 | 625 |
622 tabLoopIteration++; | 626 tabLoopIteration++; |
623 } | 627 } |
624 } | 628 } |
OLD | NEW |