From 9d608ff14177cd665f6b2ead639415bda935fbe2 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Thu, 16 Nov 2017 14:17:17 +0000 Subject: Cleanup CJX_Node::GetAttribute This CL renames GetAttribute to TryAttribute and changes to return a pdfium::Optional instead of a boolean with an out parameter. GetAttribute is then added to call TryAttribute to mirror the other methods in the file. Change-Id: I875dac120776af7c53fe069e4dd36e5486838447 Reviewed-on: https://pdfium-review.googlesource.com/18514 Commit-Queue: dsinclair Reviewed-by: Tom Sepez --- fxjs/cfxjse_formcalc_context.cpp | 8 +- fxjs/cjx_node.cpp | 124 ++++++++++++------------ fxjs/cjx_node.h | 11 ++- xfa/fxfa/cxfa_ffpageview.cpp | 9 +- xfa/fxfa/cxfa_textprovider.cpp | 14 ++- xfa/fxfa/parser/cxfa_dataexporter.cpp | 41 ++++---- xfa/fxfa/parser/cxfa_imagedata.cpp | 8 +- xfa/fxfa/parser/cxfa_measurement.cpp | 40 ++++---- xfa/fxfa/parser/cxfa_measurement.h | 2 +- xfa/fxfa/parser/cxfa_node.cpp | 11 ++- xfa/fxfa/parser/cxfa_nodelocale.cpp | 8 +- xfa/fxfa/parser/xfa_document_datamerger_imp.cpp | 16 +-- 12 files changed, 152 insertions(+), 140 deletions(-) diff --git a/fxjs/cfxjse_formcalc_context.cpp b/fxjs/cfxjse_formcalc_context.cpp index 30fa18737b..e7e0e48871 100644 --- a/fxjs/cfxjse_formcalc_context.cpp +++ b/fxjs/cfxjse_formcalc_context.cpp @@ -5966,8 +5966,12 @@ int32_t CFXJSE_FormCalcContext::ResolveObjects( ASSERT(pNode); if (bHasNoResolveName) { WideString wsName; - if (CXFA_Node* pXFANode = pNode->AsNode()) - pXFANode->JSNode()->GetAttribute(XFA_Attribute::Name, wsName, false); + if (CXFA_Node* pXFANode = pNode->AsNode()) { + pdfium::Optional ret = + pXFANode->JSNode()->TryAttribute(XFA_Attribute::Name, false); + if (ret) + wsName = *ret; + } if (wsName.IsEmpty()) wsName = L"#" + pNode->GetClassName(); diff --git a/fxjs/cjx_node.cpp b/fxjs/cjx_node.cpp index 860171a6f1..7ebf5da25b 100644 --- a/fxjs/cjx_node.cpp +++ b/fxjs/cjx_node.cpp @@ -255,12 +255,19 @@ bool CJX_Node::SetAttribute(const WideStringView& wsAttr, return true; } -bool CJX_Node::GetAttribute(XFA_Attribute eAttr, - WideString& wsValue, - bool bUseDefault) { +WideString CJX_Node::GetAttribute(const WideStringView& attr) { + return TryAttribute(attr, true).value_or(WideString()); +} + +WideString CJX_Node::GetAttribute(XFA_Attribute attr) { + return TryAttribute(attr, true).value_or(WideString()); +} + +pdfium::Optional CJX_Node::TryAttribute(XFA_Attribute eAttr, + bool bUseDefault) { const XFA_ATTRIBUTEINFO* pAttr = XFA_GetAttributeByID(eAttr); if (!pAttr) - return false; + return {}; XFA_AttributeType eType = pAttr->eType; if (eType == XFA_AttributeType::NotSure) { @@ -273,60 +280,54 @@ bool CJX_Node::GetAttribute(XFA_Attribute eAttr, pdfium::Optional value = TryEnum(pAttr->eName, bUseDefault); if (!value) - return false; + return {}; - wsValue = GetAttributeEnumByID(*value)->pName; - return true; + return {GetAttributeEnumByID(*value)->pName}; } - case XFA_AttributeType::CData: { - pdfium::Optional ret = TryCData(pAttr->eName, bUseDefault); - if (!ret) - return false; + case XFA_AttributeType::CData: + return TryCData(pAttr->eName, bUseDefault); - wsValue = *ret; - return true; - } case XFA_AttributeType::Boolean: { bool bValue; if (!TryBoolean(pAttr->eName, bValue, bUseDefault)) - return false; - - wsValue = bValue ? L"1" : L"0"; - return true; + return {}; + return {bValue ? L"1" : L"0"}; } case XFA_AttributeType::Integer: { pdfium::Optional iValue = TryInteger(pAttr->eName, bUseDefault); if (!iValue) - return false; + return {}; + WideString wsValue; wsValue.Format(L"%d", *iValue); - return true; + return {wsValue}; } case XFA_AttributeType::Measure: { CXFA_Measurement mValue; if (!TryMeasure(pAttr->eName, mValue, bUseDefault)) - return false; + return {}; - mValue.ToString(&wsValue); - return true; + return {mValue.ToString()}; } default: - return false; + break; } + return {}; } -bool CJX_Node::GetAttribute(const WideStringView& wsAttr, - WideString& wsValue, - bool bUseDefault) { +pdfium::Optional CJX_Node::TryAttribute( + const WideStringView& wsAttr, + bool bUseDefault) { const XFA_ATTRIBUTEINFO* pAttributeInfo = XFA_GetAttributeByName(wsAttr); if (pAttributeInfo) - return GetAttribute(pAttributeInfo->eName, wsValue, bUseDefault); + return TryAttribute(pAttributeInfo->eName, bUseDefault); void* pKey = GetMapKey_Custom(wsAttr); WideStringView wsValueC; - if (GetMapModuleString(pKey, wsValueC)) - wsValue = wsValueC; - return true; + if (!GetMapModuleString(pKey, wsValueC)) + return {}; + + return {WideString(wsValueC)}; } void CJX_Node::RemoveAttribute(const WideStringView& wsAttr) { @@ -542,9 +543,7 @@ void CJX_Node::Script_TreeClass_All(CFXJSE_Value* pValue, } uint32_t dwFlag = XFA_RESOLVENODE_Siblings | XFA_RESOLVENODE_ALL; - WideString wsName; - GetAttribute(XFA_Attribute::Name, wsName, true); - WideString wsExpression = wsName + L"[*]"; + WideString wsExpression = GetAttribute(XFA_Attribute::Name) + L"[*]"; ResolveNodeList(pValue, wsExpression, dwFlag, nullptr); } @@ -667,14 +666,14 @@ void CJX_Node::Script_NodeClass_GetAttribute(CFXJSE_Arguments* pArguments) { return; } + CFXJSE_Value* pValue = pArguments->GetReturnValue(); + if (!pValue) + return; + WideString wsExpression = WideString::FromUTF8(pArguments->GetUTF8String(0).AsStringView()); - WideString wsValue; - GetAttribute(wsExpression.AsStringView(), wsValue, true); - - CFXJSE_Value* pValue = pArguments->GetReturnValue(); - if (pValue) - pValue->SetString(wsValue.UTF8Encode().AsStringView()); + pValue->SetString( + GetAttribute(wsExpression.AsStringView()).UTF8Encode().AsStringView()); } void CJX_Node::Script_NodeClass_GetElement(CFXJSE_Arguments* pArguments) { @@ -1251,9 +1250,7 @@ void CJX_Node::Script_Attribute_String(CFXJSE_Value* pValue, bool bSetting, XFA_Attribute eAttribute) { if (!bSetting) { - WideString wsValue; - GetAttribute(eAttribute, wsValue, true); - pValue->SetString(wsValue.UTF8Encode().AsStringView()); + pValue->SetString(GetAttribute(eAttribute).UTF8Encode().AsStringView()); return; } @@ -1322,10 +1319,7 @@ void CJX_Node::Script_Attribute_StringRead(CFXJSE_Value* pValue, ThrowInvalidPropertyException(); return; } - - WideString wsValue; - GetAttribute(eAttribute, wsValue, true); - pValue->SetString(wsValue.UTF8Encode().AsStringView()); + pValue->SetString(GetAttribute(eAttribute).UTF8Encode().AsStringView()); } void CJX_Node::Script_WsdlConnection_Execute(CFXJSE_Arguments* pArguments) { @@ -1575,18 +1569,14 @@ void CJX_Node::Script_Som_BorderWidth(CFXJSE_Value* pValue, return; CXFA_BorderData borderData = pWidgetData->GetBorderData(true); - int32_t iSize = borderData.CountEdges(); - WideString wsThickness; if (bSetting) { CXFA_Measurement thickness = borderData.GetEdgeData(0).GetMSThickness(); - thickness.ToString(&wsThickness); - - pValue->SetString(wsThickness.UTF8Encode().AsStringView()); + pValue->SetString(thickness.ToString().UTF8Encode().AsStringView()); return; } - wsThickness = pValue->ToWideString(); - for (int32_t i = 0; i < iSize; ++i) { + WideString wsThickness = pValue->ToWideString(); + for (int32_t i = 0; i < borderData.CountEdges(); ++i) { borderData.GetEdgeData(i).SetMSThickness( CXFA_Measurement(wsThickness.AsStringView())); } @@ -2801,9 +2791,9 @@ void CJX_Node::Script_Form_Checksum(CFXJSE_Value* pValue, return; } - WideString wsChecksum; - GetAttribute(XFA_Attribute::Checksum, wsChecksum, false); - pValue->SetString(wsChecksum.UTF8Encode().AsStringView()); + pdfium::Optional checksum = + TryAttribute(XFA_Attribute::Checksum, false); + pValue->SetString(checksum ? checksum->UTF8Encode().AsStringView() : ""); } void CJX_Node::Script_Packet_GetAttribute(CFXJSE_Arguments* pArguments) { @@ -3461,13 +3451,17 @@ bool CJX_Node::SetContent(const WideString& wsContent, case XFA_ObjectType::ContentNode: { WideString wsContentType; if (GetXFANode()->GetElementType() == XFA_Element::ExData) { - GetAttribute(XFA_Attribute::ContentType, wsContentType, false); + pdfium::Optional ret = + TryAttribute(XFA_Attribute::ContentType, false); + if (ret) + wsContentType = *ret; if (wsContentType == L"text/html") { wsContentType = L""; SetAttribute(XFA_Attribute::ContentType, wsContentType.AsStringView(), false); } } + CXFA_Node* pContentRawDataNode = GetXFANode()->GetNodeItem(XFA_NODEITEM_FirstChild); if (!pContentRawDataNode) { @@ -3555,12 +3549,14 @@ pdfium::Optional CJX_Node::TryContent(bool bScriptModify, if (!pContentRawDataNode) { XFA_Element element = XFA_Element::Sharptext; if (GetXFANode()->GetElementType() == XFA_Element::ExData) { - WideString wsContentType; - GetAttribute(XFA_Attribute::ContentType, wsContentType, false); - if (wsContentType == L"text/html") - element = XFA_Element::SharpxHTML; - else if (wsContentType == L"text/xml") - element = XFA_Element::Sharpxml; + pdfium::Optional contentType = + TryAttribute(XFA_Attribute::ContentType, false); + if (contentType) { + if (*contentType == L"text/html") + element = XFA_Element::SharpxHTML; + else if (*contentType == L"text/xml") + element = XFA_Element::Sharpxml; + } } pContentRawDataNode = GetXFANode()->CreateSamePacketNode(element); GetXFANode()->InsertChild(pContentRawDataNode, nullptr); diff --git a/fxjs/cjx_node.h b/fxjs/cjx_node.h index fca3c9f8a7..81af0dfe73 100644 --- a/fxjs/cjx_node.h +++ b/fxjs/cjx_node.h @@ -47,10 +47,13 @@ class CJX_Node : public CJX_Object { bool SetAttribute(const WideStringView& wsAttr, const WideStringView& wsValue, bool bNotify); - bool GetAttribute(const WideStringView& wsAttr, - WideString& wsValue, - bool bUseDefault); - bool GetAttribute(XFA_Attribute eAttr, WideString& wsValue, bool bUseDefault); + WideString GetAttribute(const WideStringView& attr); + WideString GetAttribute(XFA_Attribute attr); + pdfium::Optional TryAttribute(const WideStringView& wsAttr, + bool bUseDefault); + pdfium::Optional TryAttribute(XFA_Attribute eAttr, + bool bUseDefault); + bool SetAttributeValue(const WideString& wsValue, const WideString& wsXMLValue, bool bNotify, diff --git a/xfa/fxfa/cxfa_ffpageview.cpp b/xfa/fxfa/cxfa_ffpageview.cpp index 3c88a121da..26bdc26acd 100644 --- a/xfa/fxfa/cxfa_ffpageview.cpp +++ b/xfa/fxfa/cxfa_ffpageview.cpp @@ -314,11 +314,10 @@ CXFA_FFWidget* CXFA_FFTabOrderPageWidgetIterator::GetTraverseWidget( CXFA_Node* pTraverse = pTraversal->GetChild(0, XFA_Element::Traverse, false); if (pTraverse) { - WideString wsTraverseWidgetName; - if (pTraverse->JSNode()->GetAttribute(XFA_Attribute::Ref, - wsTraverseWidgetName, true)) { - return FindWidgetByName(wsTraverseWidgetName, pWidget); - } + pdfium::Optional traverseWidgetName = + pTraverse->JSNode()->TryAttribute(XFA_Attribute::Ref, true); + if (traverseWidgetName) + return FindWidgetByName(*traverseWidgetName, pWidget); } } return nullptr; diff --git a/xfa/fxfa/cxfa_textprovider.cpp b/xfa/fxfa/cxfa_textprovider.cpp index e23fdec01a..544a5c26b9 100644 --- a/xfa/fxfa/cxfa_textprovider.cpp +++ b/xfa/fxfa/cxfa_textprovider.cpp @@ -45,10 +45,9 @@ CXFA_Node* CXFA_TextProvider::GetTextNode(bool& bRichText) { CXFA_Node* pChildNode = pValueNode->GetNodeItem(XFA_NODEITEM_FirstChild); if (pChildNode && pChildNode->GetElementType() == XFA_Element::ExData) { - WideString wsContentType; - pChildNode->JSNode()->GetAttribute(XFA_Attribute::ContentType, - wsContentType, false); - if (wsContentType == L"text/html") + pdfium::Optional contentType = + pChildNode->JSNode()->TryAttribute(XFA_Attribute::ContentType, false); + if (contentType && *contentType == L"text/html") bRichText = true; } return pChildNode; @@ -84,10 +83,9 @@ CXFA_Node* CXFA_TextProvider::GetTextNode(bool& bRichText) { CXFA_Node* pChildNode = pValueNode->GetNodeItem(XFA_NODEITEM_FirstChild); if (pChildNode && pChildNode->GetElementType() == XFA_Element::ExData) { - WideString wsContentType; - pChildNode->JSNode()->GetAttribute(XFA_Attribute::ContentType, - wsContentType, false); - if (wsContentType == L"text/html") + pdfium::Optional contentType = + pChildNode->JSNode()->TryAttribute(XFA_Attribute::ContentType, false); + if (contentType && *contentType == L"text/html") bRichText = true; } return pChildNode; diff --git a/xfa/fxfa/parser/cxfa_dataexporter.cpp b/xfa/fxfa/parser/cxfa_dataexporter.cpp index 35ad4adccf..f7715dc374 100644 --- a/xfa/fxfa/parser/cxfa_dataexporter.cpp +++ b/xfa/fxfa/parser/cxfa_dataexporter.cpp @@ -90,16 +90,18 @@ void SaveAttribute(CXFA_Node* pNode, const WideStringView& wsName, bool bProto, WideString& wsOutput) { - WideString wsValue; - if ((!bProto && !pNode->JSNode()->HasAttribute(eName)) || - !pNode->JSNode()->GetAttribute(eName, wsValue, false)) { + if (!bProto && !pNode->JSNode()->HasAttribute(eName)) return; - } - wsValue = ExportEncodeAttribute(wsValue); + + pdfium::Optional value = + pNode->JSNode()->TryAttribute(eName, false); + if (!value) + return; + wsOutput += L" "; wsOutput += wsName; wsOutput += L"=\""; - wsOutput += wsValue; + wsOutput += ExportEncodeAttribute(*value); wsOutput += L"\""; } @@ -196,11 +198,10 @@ void RegenerateFormFile_Changed(CXFA_Node* pNode, if (!pRawValueNode) break; - WideString wsContentType; - pNode->JSNode()->GetAttribute(XFA_Attribute::ContentType, wsContentType, - false); + pdfium::Optional contentType = + pNode->JSNode()->TryAttribute(XFA_Attribute::ContentType, false); if (pRawValueNode->GetElementType() == XFA_Element::SharpxHTML && - wsContentType == L"text/html") { + (contentType && *contentType == L"text/html")) { CFX_XMLNode* pExDataXML = pNode->GetXMLMappingNode(); if (!pExDataXML) break; @@ -219,25 +220,25 @@ void RegenerateFormFile_Changed(CXFA_Node* pNode, wsChildren += WideString::FromUTF8( ByteStringView(pMemStream->GetBuffer(), pMemStream->GetSize())); } else if (pRawValueNode->GetElementType() == XFA_Element::Sharpxml && - wsContentType == L"text/xml") { - WideString wsRawValue; - pRawValueNode->JSNode()->GetAttribute(XFA_Attribute::Value, wsRawValue, - false); - if (wsRawValue.IsEmpty()) + (contentType && *contentType == L"text/xml")) { + pdfium::Optional rawValue = + pRawValueNode->JSNode()->TryAttribute(XFA_Attribute::Value, false); + if (!rawValue || rawValue->IsEmpty()) break; std::vector wsSelTextArray; size_t iStart = 0; - auto iEnd = wsRawValue.Find(L'\n', iStart); - iEnd = !iEnd.has_value() ? wsRawValue.GetLength() : iEnd; + auto iEnd = rawValue->Find(L'\n', iStart); + iEnd = !iEnd.has_value() ? rawValue->GetLength() : iEnd; while (iEnd.has_value() && iEnd >= iStart) { wsSelTextArray.push_back( - wsRawValue.Mid(iStart, iEnd.value() - iStart)); + rawValue->Mid(iStart, iEnd.value() - iStart)); iStart = iEnd.value() + 1; - if (iStart >= wsRawValue.GetLength()) + if (iStart >= rawValue->GetLength()) break; - iEnd = wsRawValue.Find(L'\n', iStart); + iEnd = rawValue->Find(L'\n', iStart); } + CXFA_Node* pParentNode = pNode->GetNodeItem(XFA_NODEITEM_Parent); ASSERT(pParentNode); CXFA_Node* pGrandparentNode = diff --git a/xfa/fxfa/parser/cxfa_imagedata.cpp b/xfa/fxfa/parser/cxfa_imagedata.cpp index 2ad891d7ec..7888c34205 100644 --- a/xfa/fxfa/parser/cxfa_imagedata.cpp +++ b/xfa/fxfa/parser/cxfa_imagedata.cpp @@ -35,7 +35,13 @@ bool CXFA_ImageData::GetHref(WideString& wsHref) { wsHref = *ret; return true; } - return m_pNode->JSNode()->GetAttribute(XFA_Attribute::Href, wsHref, true); + pdfium::Optional ret = + m_pNode->JSNode()->TryAttribute(XFA_Attribute::Href, true); + if (!ret) + return false; + + wsHref = *ret; + return true; } XFA_ATTRIBUTEENUM CXFA_ImageData::GetTransferEncoding() { diff --git a/xfa/fxfa/parser/cxfa_measurement.cpp b/xfa/fxfa/parser/cxfa_measurement.cpp index 053f9d1c47..91e39af969 100644 --- a/xfa/fxfa/parser/cxfa_measurement.cpp +++ b/xfa/fxfa/parser/cxfa_measurement.cpp @@ -45,36 +45,38 @@ void CXFA_Measurement::SetString(const WideStringView& wsMeasure) { Set(fValue, eUnit); } -bool CXFA_Measurement::ToString(WideString* wsMeasure) const { +WideString CXFA_Measurement::ToString() const { + WideString wsMeasure; switch (GetUnit()) { case XFA_Unit::Mm: - wsMeasure->Format(L"%.8gmm", GetValue()); - return true; + wsMeasure.Format(L"%.8gmm", GetValue()); + break; case XFA_Unit::Pt: - wsMeasure->Format(L"%.8gpt", GetValue()); - return true; + wsMeasure.Format(L"%.8gpt", GetValue()); + break; case XFA_Unit::In: - wsMeasure->Format(L"%.8gin", GetValue()); - return true; + wsMeasure.Format(L"%.8gin", GetValue()); + break; case XFA_Unit::Cm: - wsMeasure->Format(L"%.8gcm", GetValue()); - return true; + wsMeasure.Format(L"%.8gcm", GetValue()); + break; case XFA_Unit::Mp: - wsMeasure->Format(L"%.8gmp", GetValue()); - return true; + wsMeasure.Format(L"%.8gmp", GetValue()); + break; case XFA_Unit::Pc: - wsMeasure->Format(L"%.8gpc", GetValue()); - return true; + wsMeasure.Format(L"%.8gpc", GetValue()); + break; case XFA_Unit::Em: - wsMeasure->Format(L"%.8gem", GetValue()); - return true; + wsMeasure.Format(L"%.8gem", GetValue()); + break; case XFA_Unit::Percent: - wsMeasure->Format(L"%.8g%%", GetValue()); - return true; + wsMeasure.Format(L"%.8g%%", GetValue()); + break; default: - wsMeasure->Format(L"%.8g", GetValue()); - return false; + wsMeasure.Format(L"%.8g", GetValue()); + break; } + return wsMeasure; } float CXFA_Measurement::ToUnit(XFA_Unit eUnit) const { diff --git a/xfa/fxfa/parser/cxfa_measurement.h b/xfa/fxfa/parser/cxfa_measurement.h index 2f6af3d43c..d83af246b8 100644 --- a/xfa/fxfa/parser/cxfa_measurement.h +++ b/xfa/fxfa/parser/cxfa_measurement.h @@ -27,7 +27,7 @@ class CXFA_Measurement { XFA_Unit GetUnit() const { return m_eUnit; } float GetValue() const { return m_fValue; } - bool ToString(WideString* wsMeasure) const; + WideString ToString() const; float ToUnit(XFA_Unit eUnit) const; private: diff --git a/xfa/fxfa/parser/cxfa_node.cpp b/xfa/fxfa/parser/cxfa_node.cpp index 90579ff5e2..465529e777 100644 --- a/xfa/fxfa/parser/cxfa_node.cpp +++ b/xfa/fxfa/parser/cxfa_node.cpp @@ -198,8 +198,9 @@ CXFA_Node* CXFA_Node::Clone(bool bRecursive) { if (IsNeedSavingXMLNode()) { std::unique_ptr pCloneXML; if (IsAttributeInXML()) { - WideString wsName; - JSNode()->GetAttribute(XFA_Attribute::Name, wsName, false); + WideString wsName = JSNode() + ->TryAttribute(XFA_Attribute::Name, false) + .value_or(WideString()); auto pCloneXMLElement = pdfium::MakeUnique(wsName); WideString wsValue = JSNode()->GetCData(XFA_Attribute::Value); if (!wsValue.IsEmpty()) @@ -867,8 +868,10 @@ bool CXFA_Node::RemoveChild(CXFA_Node* pNode, bool bNotify) { pNode->JSNode()->GetCData(XFA_Attribute::QualifiedName); pXMLElement->RemoveAttribute(wsAttributeName.c_str()); } - WideString wsName; - pNode->JSNode()->GetAttribute(XFA_Attribute::Name, wsName, false); + + WideString wsName = pNode->JSNode() + ->TryAttribute(XFA_Attribute::Name, false) + .value_or(WideString()); CFX_XMLElement* pNewXMLElement = new CFX_XMLElement(wsName); WideString wsValue = JSNode()->GetCData(XFA_Attribute::Value); if (!wsValue.IsEmpty()) diff --git a/xfa/fxfa/parser/cxfa_nodelocale.cpp b/xfa/fxfa/parser/cxfa_nodelocale.cpp index 25086922a7..da64c4a04c 100644 --- a/xfa/fxfa/parser/cxfa_nodelocale.cpp +++ b/xfa/fxfa/parser/cxfa_nodelocale.cpp @@ -135,11 +135,9 @@ CXFA_Node* CXFA_NodeLocale::GetNodeByName(CXFA_Node* pParent, CXFA_Node* pChild = pParent ? pParent->GetNodeItem(XFA_NODEITEM_FirstChild) : nullptr; while (pChild) { - WideString wsChild; - if (pChild->JSNode()->GetAttribute(XFA_Attribute::Name, wsChild, true)) { - if (wsChild == wsName) - return pChild; - } + if (pChild->JSNode()->GetAttribute(XFA_Attribute::Name) == wsName) + return pChild; + pChild = pChild->GetNodeItem(XFA_NODEITEM_NextSibling); } return nullptr; diff --git a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp index 29bcd5f3b9..4cf7601531 100644 --- a/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp +++ b/xfa/fxfa/parser/xfa_document_datamerger_imp.cpp @@ -88,13 +88,15 @@ bool FormValueNode_SetChildContent(CXFA_Node* pValueNode, if (!pContentRawDataNode) { XFA_Element element = XFA_Element::Sharptext; if (pChildNode->GetElementType() == XFA_Element::ExData) { - WideString wsContentType; - pChildNode->JSNode()->GetAttribute(XFA_Attribute::ContentType, - wsContentType, false); - if (wsContentType == L"text/html") - element = XFA_Element::SharpxHTML; - else if (wsContentType == L"text/xml") - element = XFA_Element::Sharpxml; + pdfium::Optional contentType = + pChildNode->JSNode()->TryAttribute(XFA_Attribute::ContentType, + false); + if (contentType) { + if (*contentType == L"text/html") + element = XFA_Element::SharpxHTML; + else if (*contentType == L"text/xml") + element = XFA_Element::Sharpxml; + } } pContentRawDataNode = pChildNode->CreateSamePacketNode(element); pChildNode->InsertChild(pContentRawDataNode, nullptr); -- cgit v1.2.3