зеркало из https://github.com/mozilla/gecko-dev.git
Make XML serializer output an encoding="..." which matches the actual encoding
it's serializing to. Bug 361933, r+sr=sicking
This commit is contained in:
Родитель
5830c027a5
Коммит
a3f56eb552
|
@ -67,7 +67,8 @@ interface nsIDOMSerializer : nsISupports
|
|||
* be any node, including a Document.
|
||||
* @param stream The byte stream to which the subtree is serialized.
|
||||
* @param charset The name of the character set to use for the encoding
|
||||
* to a byte stream.
|
||||
* to a byte stream. If this string is empty and root is
|
||||
* a document, the document's character set will be used.
|
||||
*/
|
||||
void serializeToStream(in nsIDOMNode root, in nsIOutputStream stream,
|
||||
in AUTF8String charset);
|
||||
|
|
|
@ -148,7 +148,7 @@ nsDOMSerializer::SerializeToStream(nsIDOMNode *aRoot,
|
|||
{
|
||||
NS_ENSURE_ARG_POINTER(aRoot);
|
||||
NS_ENSURE_ARG_POINTER(aStream);
|
||||
// The charset arg can be null, in which case we get the document's
|
||||
// The charset arg can be empty, in which case we get the document's
|
||||
// charset and use that when serializing.
|
||||
|
||||
if (!nsContentUtils::CanCallerAccess(aRoot)) {
|
||||
|
|
|
@ -145,7 +145,7 @@ nsHTMLContentSerializer::Init(PRUint32 aFlags, PRUint32 aWrapColumn,
|
|||
|
||||
mPreLevel = 0;
|
||||
|
||||
mCharSet = aCharSet;
|
||||
mCharset = aCharSet;
|
||||
|
||||
// set up entity converter if we are going to need it
|
||||
if (mFlags & nsIDocumentEncoder::OutputEncodeW3CEntities) {
|
||||
|
@ -496,7 +496,7 @@ nsHTMLContentSerializer::EscapeURI(const nsAString& aURI, nsAString& aEscapedURI
|
|||
nsresult rv = NS_OK;
|
||||
|
||||
|
||||
if (!mCharSet.IsEmpty() && !IsASCII(uri)) {
|
||||
if (!mCharset.IsEmpty() && !IsASCII(uri)) {
|
||||
textToSubURI = do_GetService(NS_ITEXTTOSUBURI_CONTRACTID, &rv);
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
|
@ -511,7 +511,7 @@ nsHTMLContentSerializer::EscapeURI(const nsAString& aURI, nsAString& aEscapedURI
|
|||
while ((end = uri.FindCharInSet("%#;/?:@&=+$,", start)) != -1) {
|
||||
part = Substring(aURI, start, (end-start));
|
||||
if (textToSubURI && !IsASCII(part)) {
|
||||
rv = textToSubURI->ConvertAndEscape(mCharSet.get(), part.get(), getter_Copies(escapedURI));
|
||||
rv = textToSubURI->ConvertAndEscape(mCharset.get(), part.get(), getter_Copies(escapedURI));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
else {
|
||||
|
@ -529,7 +529,7 @@ nsHTMLContentSerializer::EscapeURI(const nsAString& aURI, nsAString& aEscapedURI
|
|||
// Escape the remaining part.
|
||||
part = Substring(aURI, start, aURI.Length()-start);
|
||||
if (textToSubURI) {
|
||||
rv = textToSubURI->ConvertAndEscape(mCharSet.get(), part.get(), getter_Copies(escapedURI));
|
||||
rv = textToSubURI->ConvertAndEscape(mCharset.get(), part.get(), getter_Copies(escapedURI));
|
||||
NS_ENSURE_SUCCESS(rv, rv);
|
||||
}
|
||||
else {
|
||||
|
|
|
@ -160,9 +160,7 @@ class nsHTMLContentSerializer : public nsXMLContentSerializer {
|
|||
PRInt32 mMaxColumn;
|
||||
nsString mLineBreak;
|
||||
|
||||
nsCString mCharSet;
|
||||
|
||||
// To keep track of startvalue of OL and first list item for nested lists
|
||||
// To keep track of startvalue of OL and first list item for nested lists
|
||||
struct olState {
|
||||
olState(PRInt32 aStart, PRBool aIsFirst):startVal(aStart),isFirstListItem(aIsFirst)
|
||||
{
|
||||
|
|
|
@ -96,6 +96,7 @@ NS_IMETHODIMP
|
|||
nsXMLContentSerializer::Init(PRUint32 flags, PRUint32 aWrapColumn,
|
||||
const char* aCharSet, PRBool aIsCopying)
|
||||
{
|
||||
mCharset = aCharSet;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
@ -1002,9 +1003,17 @@ nsXMLContentSerializer::AppendDocumentStart(nsIDOMDocument *aDocument,
|
|||
|
||||
aStr += NS_LITERAL_STRING("<?xml version=\"") + version + endQuote;
|
||||
|
||||
if (!encoding.IsEmpty()) {
|
||||
aStr += NS_LITERAL_STRING(" encoding=\"") + encoding + endQuote;
|
||||
if (!mCharset.IsEmpty()) {
|
||||
aStr += NS_LITERAL_STRING(" encoding=\"") +
|
||||
NS_ConvertASCIItoUTF16(mCharset) + endQuote;
|
||||
}
|
||||
// Otherwise just don't output an encoding attr. Not that we expect
|
||||
// mCharset to ever be empty.
|
||||
#ifdef DEBUG
|
||||
else {
|
||||
NS_WARNING("Empty mCharset? How come?");
|
||||
}
|
||||
#endif
|
||||
|
||||
if (!standalone.IsEmpty()) {
|
||||
aStr += NS_LITERAL_STRING(" standalone=\"") + standalone + endQuote;
|
||||
|
|
|
@ -153,6 +153,10 @@ class nsXMLContentSerializer : public nsIContentSerializer {
|
|||
|
||||
PRInt32 mPrefixIndex;
|
||||
nsVoidArray mNameSpaceStack;
|
||||
|
||||
// The charset that was passed to Init()
|
||||
nsCString mCharset;
|
||||
|
||||
PRPackedBool mInAttribute;
|
||||
PRPackedBool mAddNewline;
|
||||
};
|
||||
|
|
Загрузка…
Ссылка в новой задаче