From 1373da05f3c73a9fb5851ec57b6bf4d5fec05ea5 Mon Sep 17 00:00:00 2001 From: Masayuki Nakano Date: Wed, 13 Jul 2016 18:16:04 +0900 Subject: [PATCH] Bug 1286489 TSFTextStore.cpp and ContentCache.cpp shouldn't put \n, \r and \t to log file directly r=m_kato MozReview-Commit-ID: 630lZINQteb --HG-- extra : rebase_source : 9841cfdb199d1a7964d1ad4516d9862f498b0f39 --- widget/ContentCache.cpp | 34 ++++++++++++++++-- widget/windows/TSFTextStore.cpp | 62 ++++++++++++++++++++++++--------- 2 files changed, 76 insertions(+), 20 deletions(-) diff --git a/widget/ContentCache.cpp b/widget/ContentCache.cpp index df31818abd72..8ae6f2526f4d 100644 --- a/widget/ContentCache.cpp +++ b/widget/ContentCache.cpp @@ -69,6 +69,34 @@ public: virtual ~GetWritingModeName() {} }; +class GetEscapedUTF8String final : public NS_ConvertUTF16toUTF8 +{ +public: + explicit GetEscapedUTF8String(const nsAString& aString) + : NS_ConvertUTF16toUTF8(aString) + { + Escape(); + } + explicit GetEscapedUTF8String(const char16ptr_t aString) + : NS_ConvertUTF16toUTF8(aString) + { + Escape(); + } + GetEscapedUTF8String(const char16ptr_t aString, uint32_t aLength) + : NS_ConvertUTF16toUTF8(aString, aLength) + { + Escape(); + } + +private: + void Escape() + { + ReplaceSubstring("\r", "\\r"); + ReplaceSubstring("\n", "\\n"); + ReplaceSubstring("\t", "\\t"); + } +}; + /***************************************************************************** * mozilla::ContentCache *****************************************************************************/ @@ -548,7 +576,7 @@ ContentCacheInParent::HandleQueryContentEvent(WidgetQueryContentEvent& aEvent, "Succeeded, aEvent={ mReply={ mOffset=%u, mString=\"%s\", " "mReversed=%s, mHasSelection=%s, mWritingMode=%s } }", this, aEvent.mReply.mOffset, - NS_ConvertUTF16toUTF8(aEvent.mReply.mString).get(), + GetEscapedUTF8String(aEvent.mReply.mString).get(), GetBoolName(aEvent.mReply.mReversed), GetBoolName(aEvent.mReply.mHasSelection), GetWritingModeName(aEvent.mReply.mWritingMode).get())); @@ -636,7 +664,7 @@ ContentCacheInParent::HandleQueryContentEvent(WidgetQueryContentEvent& aEvent, "Succeeded, aEvent={ mReply={ mOffset=%u, mString=\"%s\", " "mWritingMode=%s, mRect=%s } }", this, aEvent.mReply.mOffset, - NS_ConvertUTF16toUTF8(aEvent.mReply.mString).get(), + GetEscapedUTF8String(aEvent.mReply.mString).get(), GetWritingModeName(aEvent.mReply.mWritingMode).get(), GetRectText(aEvent.mReply.mRect).get())); break; @@ -886,7 +914,7 @@ ContentCacheInParent::OnCompositionEvent(const WidgetCompositionEvent& aEvent) "mPendingEventsNeedingAck=%u, mIsComposing=%s, " "mCommitStringByRequest=0x%p", this, ToChar(aEvent.mMessage), - NS_ConvertUTF16toUTF8(aEvent.mData).get(), aEvent.mData.Length(), + GetEscapedUTF8String(aEvent.mData).get(), aEvent.mData.Length(), aEvent.mRanges ? aEvent.mRanges->Length() : 0, mPendingEventsNeedingAck, GetBoolName(mIsComposing), mCommitStringByRequest)); diff --git a/widget/windows/TSFTextStore.cpp b/widget/windows/TSFTextStore.cpp index 38e9e30e83de..495c44a432bb 100644 --- a/widget/windows/TSFTextStore.cpp +++ b/widget/windows/TSFTextStore.cpp @@ -663,6 +663,34 @@ public: virtual ~GetWritingModeName() {} }; +class GetEscapedUTF8String final : public NS_ConvertUTF16toUTF8 +{ +public: + explicit GetEscapedUTF8String(const nsAString& aString) + : NS_ConvertUTF16toUTF8(aString) + { + Escape(); + } + explicit GetEscapedUTF8String(const char16ptr_t aString) + : NS_ConvertUTF16toUTF8(aString) + { + Escape(); + } + GetEscapedUTF8String(const char16ptr_t aString, uint32_t aLength) + : NS_ConvertUTF16toUTF8(aString, aLength) + { + Escape(); + } + +private: + void Escape() + { + ReplaceSubstring("\r", "\\r"); + ReplaceSubstring("\n", "\\n"); + ReplaceSubstring("\t", "\\t"); + } +}; + /******************************************************************/ /* InputScopeImpl */ /******************************************************************/ @@ -1690,7 +1718,7 @@ TSFTextStore::FlushPendingActions() ("0x%p TSFTextStore::FlushPendingActions() " "flushing COMPOSITION_UPDATE={ mData=\"%s\", " "mRanges=0x%p, mRanges->Length()=%d }", - this, NS_ConvertUTF16toUTF8(action.mData).get(), + this, GetEscapedUTF8String(action.mData).get(), action.mRanges.get(), action.mRanges ? action.mRanges->Length() : 0)); @@ -1732,7 +1760,7 @@ TSFTextStore::FlushPendingActions() MOZ_LOG(sTextStoreLog, LogLevel::Debug, ("0x%p TSFTextStore::FlushPendingActions() " "flushing COMPOSITION_END={ mData=\"%s\" }", - this, NS_ConvertUTF16toUTF8(action.mData).get())); + this, GetEscapedUTF8String(action.mData).get())); // Dispatching eCompositionCommit causes a DOM text event, then, // the IME will be notified of NOTIFY_IME_OF_COMPOSITION_EVENT_HANDLED. @@ -2056,10 +2084,10 @@ TSFTextStore::ContentForTSFRef() "mContentForTSF={ mText=\"%s\" (Length()=%u), " "mLastCompositionString=\"%s\" (Length()=%u), " "mMinTextModifiedOffset=%u }", - this, mContentForTSF.Text().Length() <= 20 ? - NS_ConvertUTF16toUTF8(mContentForTSF.Text()).get() : "", + this, mContentForTSF.Text().Length() <= 40 ? + GetEscapedUTF8String(mContentForTSF.Text()).get() : "", mContentForTSF.Text().Length(), - NS_ConvertUTF16toUTF8(mContentForTSF.LastCompositionString()).get(), + GetEscapedUTF8String(mContentForTSF.LastCompositionString()).get(), mContentForTSF.LastCompositionString().Length(), mContentForTSF.MinTextModifiedOffset())); @@ -2455,7 +2483,7 @@ TSFTextStore::RecordCompositionUpdateAction() "mComposition={ mView=0x%p, mStart=%d, mString=\"%s\" " "(Length()=%d) }", this, mComposition.mView.get(), mComposition.mStart, - NS_ConvertUTF16toUTF8(mComposition.mString).get(), + GetEscapedUTF8String(mComposition.mString).get(), mComposition.mString.Length())); if (!mComposition.IsComposing()) { @@ -2931,7 +2959,7 @@ TSFTextStore::SetText(DWORD dwFlags, "not-specified", acpStart, acpEnd, pchText, pchText && cch ? - NS_ConvertUTF16toUTF8(pchText, cch).get() : "", + GetEscapedUTF8String(pchText, cch).get() : "", cch, pChange, GetBoolName(mComposition.IsComposing()))); // Per SDK documentation, and since we don't have better @@ -3894,7 +3922,7 @@ TSFTextStore::InsertTextAtSelection(DWORD dwFlags, dwFlags == TF_IAS_NOQUERY ? "TF_IAS_NOQUERY" : dwFlags == TF_IAS_QUERYONLY ? "TF_IAS_QUERYONLY" : "Unknown", pchText, - pchText && cch ? NS_ConvertUTF16toUTF8(pchText, cch).get() : "", + pchText && cch ? GetEscapedUTF8String(pchText, cch).get() : "", cch, pacpStart, pacpEnd, pChange, GetBoolName(mComposition.IsComposing()))); @@ -3990,7 +4018,7 @@ TSFTextStore::InsertTextAtSelectionInternal(const nsAString& aInsertStr, MOZ_LOG(sTextStoreLog, LogLevel::Debug, ("0x%p TSFTextStore::InsertTextAtSelectionInternal(" "aInsertStr=\"%s\", aTextChange=0x%p), IsComposing=%s", - this, NS_ConvertUTF16toUTF8(aInsertStr).get(), aTextChange, + this, GetEscapedUTF8String(aInsertStr).get(), aTextChange, GetBoolName(mComposition.IsComposing()))); Content& contentForTSF = ContentForTSFRef(); @@ -4023,7 +4051,7 @@ TSFTextStore::InsertTextAtSelectionInternal(const nsAString& aInsertStr, "(Length()=%u) }", this, compositionStart->mSelectionStart, compositionStart->mSelectionLength, - NS_ConvertUTF16toUTF8(compositionEnd->mData).get(), + GetEscapedUTF8String(compositionEnd->mData).get(), compositionEnd->mData.Length())); } @@ -4183,7 +4211,7 @@ TSFTextStore::RecordCompositionEndAction() ("0x%p TSFTextStore::RecordCompositionEndAction(), " "mComposition={ mView=0x%p, mString=\"%s\" }", this, mComposition.mView.get(), - NS_ConvertUTF16toUTF8(mComposition.mString).get())); + GetEscapedUTF8String(mComposition.mString).get())); MOZ_ASSERT(mComposition.IsComposing()); @@ -4346,7 +4374,7 @@ TSFTextStore::OnUpdateComposition(ITfCompositionView* pComposition, "mComposition={ mStart=%ld, mString=\"%s\" }, " "SelectionForTSFRef()={ acpStart=%ld, acpEnd=%ld, style.ase=%s }", this, mComposition.mStart, - NS_ConvertUTF16toUTF8(mComposition.mString).get(), + GetEscapedUTF8String(mComposition.mString).get(), selectionForTSF.StartOffset(), selectionForTSF.EndOffset(), GetActiveSelEndName(selectionForTSF.ActiveSelEnd()))); } @@ -4360,7 +4388,7 @@ TSFTextStore::OnEndComposition(ITfCompositionView* pComposition) ("0x%p TSFTextStore::OnEndComposition(pComposition=0x%p), " "mComposition={ mView=0x%p, mString=\"%s\" }", this, pComposition, mComposition.mView.get(), - NS_ConvertUTF16toUTF8(mComposition.mString).get())); + GetEscapedUTF8String(mComposition.mString).get())); AutoPendingActionAndContentFlusher flusher(this); @@ -5203,7 +5231,7 @@ TSFTextStore::CommitCompositionInternal(bool aDiscard) "mComposition.mString=\"%s\"", this, GetBoolName(aDiscard), mSink.get(), mContext.get(), mComposition.mView.get(), - NS_ConvertUTF16toUTF8(mComposition.mString).get())); + GetEscapedUTF8String(mComposition.mString).get())); // If the document is locked, TSF will fail to commit composition since // TSF needs another document lock. So, let's put off the request. @@ -5828,9 +5856,9 @@ TSFTextStore::Content::ReplaceTextWith(LONG aStart, "aLength=%d, aReplaceString=\"%s\"), mComposition={ mStart=%d, " "mString=\"%s\" }, mLastCompositionString=\"%s\", " "mMinTextModifiedOffset=%u, firstDifferentOffset=%u", - this, aStart, aLength, NS_ConvertUTF16toUTF8(aReplaceString).get(), - mComposition.mStart, NS_ConvertUTF16toUTF8(mComposition.mString).get(), - NS_ConvertUTF16toUTF8(mLastCompositionString).get(), + this, aStart, aLength, GetEscapedUTF8String(aReplaceString).get(), + mComposition.mStart, GetEscapedUTF8String(mComposition.mString).get(), + GetEscapedUTF8String(mLastCompositionString).get(), mMinTextModifiedOffset, firstDifferentOffset)); } else { firstDifferentOffset =