mirror of
https://github.com/classilla/tenfourfox.git
synced 2025-01-03 20:30:00 +00:00
#632: M1249352 part 2
This commit is contained in:
parent
438bdb7265
commit
2c61821e49
@ -6,6 +6,9 @@
|
|||||||
|
|
||||||
#include "mozilla/RangedPtr.h"
|
#include "mozilla/RangedPtr.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <iterator>
|
||||||
|
|
||||||
#include "nsURLHelper.h"
|
#include "nsURLHelper.h"
|
||||||
#include "nsIFile.h"
|
#include "nsIFile.h"
|
||||||
#include "nsIURLParser.h"
|
#include "nsIURLParser.h"
|
||||||
@ -612,33 +615,36 @@ net_IsAbsoluteURL(const nsACString& uri)
|
|||||||
void
|
void
|
||||||
net_FilterURIString(const nsACString& input, nsACString& result)
|
net_FilterURIString(const nsACString& input, nsACString& result)
|
||||||
{
|
{
|
||||||
|
const char kCharsToStrip[] = "\r\n\t";
|
||||||
|
|
||||||
result.Truncate();
|
result.Truncate();
|
||||||
|
auto start = input.BeginReading();
|
||||||
|
auto end = input.EndReading();
|
||||||
|
|
||||||
nsACString::const_iterator start, end;
|
// Trim off leading and trailing invalid chars.
|
||||||
input.BeginReading(start);
|
auto charFilter = [](char c) { return static_cast<uint8_t>(c) > 0x20; };
|
||||||
input.EndReading(end);
|
auto newStart = std::find_if(start, end, charFilter);
|
||||||
|
auto newEnd = std::find_if(
|
||||||
|
std::reverse_iterator<decltype(end)>(end),
|
||||||
|
std::reverse_iterator<decltype(newStart)>(newStart),
|
||||||
|
charFilter).base();
|
||||||
|
|
||||||
// Strip C0 and space from begining
|
// Check if chars need to be stripped.
|
||||||
while (start != end) {
|
auto itr = std::find_first_of(
|
||||||
if ((uint8_t) *start > 0x20) {
|
newStart, newEnd, std::begin(kCharsToStrip), std::end(kCharsToStrip));
|
||||||
break;
|
const bool needsStrip = itr != newEnd;
|
||||||
}
|
|
||||||
start++;
|
// Just use the passed in string rather than creating new copies if no
|
||||||
|
// changes are necessary.
|
||||||
|
if (newStart == start && newEnd == end && !needsStrip) {
|
||||||
|
result = input;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MOZ_ASSERT(!*end, "input should null terminated");
|
result.Assign(Substring(newStart, newEnd));
|
||||||
// Strip C0 and space from end
|
if (needsStrip) {
|
||||||
while (end != start) {
|
result.StripChars(kCharsToStrip);
|
||||||
end--;
|
|
||||||
if ((uint8_t) *end > 0x20) {
|
|
||||||
end++;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
nsAutoCString temp(Substring(start, end));
|
|
||||||
temp.StripChars("\r\n\t");
|
|
||||||
result.Assign(temp);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(XP_WIN)
|
#if defined(XP_WIN)
|
||||||
|
Loading…
Reference in New Issue
Block a user