Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes line end and white space normalization. #196

Merged
merged 1 commit into from
Apr 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ var xml_special_to_encoded_text = {

function encodeSpecialCharactersInAttribute(attributeValue){
return attributeValue
.replace(/[\r\n\t ]+/g, ' ') // White space normalization (Note: this should normally be done by the xml parser) See: https://www.w3.org/TR/xml/#AVNormalize
.replace(/([&<"\r\n\t])/g, function(str, item){
// Special character normalization. See:
// - https://www.w3.org/TR/xml-c14n#ProcessingModel (Attribute Nodes)
Expand All @@ -66,7 +65,6 @@ function encodeSpecialCharactersInAttribute(attributeValue){

function encodeSpecialCharactersInText(text){
return text
.replace(/\r\n?/g, '\n') // Line ending normalization (Note: this should normally be done by the xml parser). See: https://www.w3.org/TR/xml/#sec-line-ends
.replace(/([&<>\r])/g, function(str, item){
// Special character normalization. See:
// - https://www.w3.org/TR/xml-c14n#ProcessingModel (Text Nodes)
Expand Down
126 changes: 63 additions & 63 deletions test/c14nWithComments-unit-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -274,72 +274,72 @@ module.exports = {

"Exclusive canonicalization works on complex xml": function (test) {
compare(test,
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\r" +
"<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\">\r" +
" <Body>\r" +
" <ACORD xmlns=\"http://www.ACORD.org/standards/PC_Surety/ACORD1.10.0/xml/\">\r" +
" <SignonRq>\r" +
" <SessKey />\r" +
" <ClientDt />\r" +
" <CustLangPref />\r" +
" <ClientApp>\r" +
" <Org p6:type=\"AssignedIdentifier\" id=\"wewe\" xmlns:p6=\"http://www.w3.org/2001/XMLSchema-instance\" />\r" +
" <Name />\r" +
" <Version />\r" +
" </ClientApp>\r" +
" <ProxyClient>\r" +
" <Org p6:type=\"AssignedIdentifier\" id=\"erer\" xmlns:p6=\"http://www.w3.org/2001/XMLSchema-instance\" />\r" +
" <Name>ererer</Name>\r" +
" <Version>dfdf</Version>\r" +
" </ProxyClient>\r" +
" </SignonRq>\r" +
" <InsuranceSvcRq>\r" +
" <RqUID />\r" +
" <SPName id=\"rter\" />\r" +
" <QuickHit xmlns=\"urn:com.thehartford.bi.acord-extensions\">\r" +
" <StateProvCd CodeListRef=\"dfdf\" xmlns=\"http://www.ACORD.org/standards/PC_Surety/ACORD1.10.0/xml/\" />\r" +
" </QuickHit>\r" +
" <WorkCompPolicyQuoteInqRq>\r" +
" <RqUID>erer</RqUID>\r" +
" <TransactionRequestDt id=\"erer\" />\r" +
" <CurCd />\r" +
" <BroadLOBCd id=\"erer\" />\r" +
" <InsuredOrPrincipal>\r" +
" <ItemIdInfo>\r" +
" <AgencyId id=\"3434\" />\r" +
" <OtherIdentifier>\r" +
" <CommercialName id=\"3434\" />\r" +
" <ContractTerm>\r" +
" <EffectiveDt id=\"3434\" />\r" +
" <StartTime id=\"3434\" />\r" +
" </ContractTerm>\r" +
" </OtherIdentifier>\r" +
" </ItemIdInfo>\r" +
" </InsuredOrPrincipal>\r" +
" <InsuredOrPrincipal>\r" +
" </InsuredOrPrincipal>\r" +
" <CommlPolicy>\r" +
" <PolicyNumber id=\"3434\" />\r" +
" <LOBCd />\r" +
" </CommlPolicy>\r" +
" <WorkCompLineBusiness>\r" +
" <LOBCd />\r" +
" <WorkCompRateState>\r" +
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
"<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
" <Body>\n" +
" <ACORD xmlns=\"http://www.ACORD.org/standards/PC_Surety/ACORD1.10.0/xml/\">\n" +
" <SignonRq>\n" +
" <SessKey />\n" +
" <ClientDt />\n" +
" <CustLangPref />\n" +
" <ClientApp>\n" +
" <Org p6:type=\"AssignedIdentifier\" id=\"wewe\" xmlns:p6=\"http://www.w3.org/2001/XMLSchema-instance\" />\n" +
" <Name />\n" +
" <Version />\n" +
" </ClientApp>\n" +
" <ProxyClient>\n" +
" <Org p6:type=\"AssignedIdentifier\" id=\"erer\" xmlns:p6=\"http://www.w3.org/2001/XMLSchema-instance\" />\n" +
" <Name>ererer</Name>\n" +
" <Version>dfdf</Version>\n" +
" </ProxyClient>\n" +
" </SignonRq>\n" +
" <InsuranceSvcRq>\n" +
" <RqUID />\n" +
" <SPName id=\"rter\" />\n" +
" <QuickHit xmlns=\"urn:com.thehartford.bi.acord-extensions\">\n" +
" <StateProvCd CodeListRef=\"dfdf\" xmlns=\"http://www.ACORD.org/standards/PC_Surety/ACORD1.10.0/xml/\" />\n" +
" </QuickHit>\n" +
" <WorkCompPolicyQuoteInqRq>\n" +
" <RqUID>erer</RqUID>\n" +
" <TransactionRequestDt id=\"erer\" />\n" +
" <CurCd />\n" +
" <BroadLOBCd id=\"erer\" />\n" +
" <InsuredOrPrincipal>\n" +
" <ItemIdInfo>\n" +
" <AgencyId id=\"3434\" />\n" +
" <OtherIdentifier>\n" +
" <CommercialName id=\"3434\" />\n" +
" <ContractTerm>\n" +
" <EffectiveDt id=\"3434\" />\n" +
" <StartTime id=\"3434\" />\n" +
" </ContractTerm>\n" +
" </OtherIdentifier>\n" +
" </ItemIdInfo>\n" +
" </InsuredOrPrincipal>\n" +
" <InsuredOrPrincipal>\n" +
" </InsuredOrPrincipal>\n" +
" <CommlPolicy>\n" +
" <PolicyNumber id=\"3434\" />\n" +
" <LOBCd />\n" +
" </CommlPolicy>\n" +
" <WorkCompLineBusiness>\n" +
" <LOBCd />\n" +
" <WorkCompRateState>\n" +
" <WorkCompLocInfo>\r" +
" </WorkCompLocInfo>\r" +
" </WorkCompRateState>\r" +
" </WorkCompLineBusiness>\r" +
" <RemarkText IdRef=\"\">\r" +
" </RemarkText>\r" +
" <RemarkText IdRef=\"2323\" id=\"3434\">\r" +
" </RemarkText>\r" +
" </WorkCompPolicyQuoteInqRq>\r" +
" </InsuranceSvcRq>\r" +
" </ACORD>\r" +
" </Body>\r" +
" </WorkCompLocInfo>\n" +
" </WorkCompRateState>\n" +
" </WorkCompLineBusiness>\n" +
" <RemarkText IdRef=\"\">\n" +
" </RemarkText>\n" +
" <RemarkText IdRef=\"2323\" id=\"3434\">\n" +
" </RemarkText>\n" +
" </WorkCompPolicyQuoteInqRq>\n" +
" </InsuranceSvcRq>\n" +
" </ACORD>\n" +
" </Body>\n" +
"</Envelope>",
"//*[local-name(.)='Body']",
"<Body xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <ACORD xmlns=\"http://www.ACORD.org/standards/PC_Surety/ACORD1.10.0/xml/\">\n <SignonRq>\n <SessKey></SessKey>\n <ClientDt></ClientDt>\n <CustLangPref></CustLangPref>\n <ClientApp>\n <Org xmlns:p6=\"http://www.w3.org/2001/XMLSchema-instance\" id=\"wewe\" p6:type=\"AssignedIdentifier\"></Org>\n <Name></Name>\n <Version></Version>\n </ClientApp>\n <ProxyClient>\n <Org xmlns:p6=\"http://www.w3.org/2001/XMLSchema-instance\" id=\"erer\" p6:type=\"AssignedIdentifier\"></Org>\n <Name>ererer</Name>\n <Version>dfdf</Version>\n </ProxyClient>\n </SignonRq>\n <InsuranceSvcRq>\n <RqUID></RqUID>\n <SPName id=\"rter\"></SPName>\n <QuickHit xmlns=\"urn:com.thehartford.bi.acord-extensions\">\n <StateProvCd xmlns=\"http://www.ACORD.org/standards/PC_Surety/ACORD1.10.0/xml/\" CodeListRef=\"dfdf\"></StateProvCd>\n </QuickHit>\n <WorkCompPolicyQuoteInqRq>\n <RqUID>erer</RqUID>\n <TransactionRequestDt id=\"erer\"></TransactionRequestDt>\n <CurCd></CurCd>\n <BroadLOBCd id=\"erer\"></BroadLOBCd>\n <InsuredOrPrincipal>\n <ItemIdInfo>\n <AgencyId id=\"3434\"></AgencyId>\n <OtherIdentifier>\n <CommercialName id=\"3434\"></CommercialName>\n <ContractTerm>\n <EffectiveDt id=\"3434\"></EffectiveDt>\n <StartTime id=\"3434\"></StartTime>\n </ContractTerm>\n </OtherIdentifier>\n </ItemIdInfo>\n </InsuredOrPrincipal>\n <InsuredOrPrincipal>\n </InsuredOrPrincipal>\n <CommlPolicy>\n <PolicyNumber id=\"3434\"></PolicyNumber>\n <LOBCd></LOBCd>\n </CommlPolicy>\n <WorkCompLineBusiness>\n <LOBCd></LOBCd>\n <WorkCompRateState>\n <WorkCompLocInfo>\n </WorkCompLocInfo>\n </WorkCompRateState>\n </WorkCompLineBusiness>\n <RemarkText IdRef=\"\">\n </RemarkText>\n <RemarkText IdRef=\"2323\" id=\"3434\">\n </RemarkText>\n </WorkCompPolicyQuoteInqRq>\n </InsuranceSvcRq>\n </ACORD>\n </Body>")
"<Body xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\">\n <ACORD xmlns=\"http://www.ACORD.org/standards/PC_Surety/ACORD1.10.0/xml/\">\n <SignonRq>\n <SessKey></SessKey>\n <ClientDt></ClientDt>\n <CustLangPref></CustLangPref>\n <ClientApp>\n <Org xmlns:p6=\"http://www.w3.org/2001/XMLSchema-instance\" id=\"wewe\" p6:type=\"AssignedIdentifier\"></Org>\n <Name></Name>\n <Version></Version>\n </ClientApp>\n <ProxyClient>\n <Org xmlns:p6=\"http://www.w3.org/2001/XMLSchema-instance\" id=\"erer\" p6:type=\"AssignedIdentifier\"></Org>\n <Name>ererer</Name>\n <Version>dfdf</Version>\n </ProxyClient>\n </SignonRq>\n <InsuranceSvcRq>\n <RqUID></RqUID>\n <SPName id=\"rter\"></SPName>\n <QuickHit xmlns=\"urn:com.thehartford.bi.acord-extensions\">\n <StateProvCd xmlns=\"http://www.ACORD.org/standards/PC_Surety/ACORD1.10.0/xml/\" CodeListRef=\"dfdf\"></StateProvCd>\n </QuickHit>\n <WorkCompPolicyQuoteInqRq>\n <RqUID>erer</RqUID>\n <TransactionRequestDt id=\"erer\"></TransactionRequestDt>\n <CurCd></CurCd>\n <BroadLOBCd id=\"erer\"></BroadLOBCd>\n <InsuredOrPrincipal>\n <ItemIdInfo>\n <AgencyId id=\"3434\"></AgencyId>\n <OtherIdentifier>\n <CommercialName id=\"3434\"></CommercialName>\n <ContractTerm>\n <EffectiveDt id=\"3434\"></EffectiveDt>\n <StartTime id=\"3434\"></StartTime>\n </ContractTerm>\n </OtherIdentifier>\n </ItemIdInfo>\n </InsuredOrPrincipal>\n <InsuredOrPrincipal>\n </InsuredOrPrincipal>\n <CommlPolicy>\n <PolicyNumber id=\"3434\"></PolicyNumber>\n <LOBCd></LOBCd>\n </CommlPolicy>\n <WorkCompLineBusiness>\n <LOBCd></LOBCd>\n <WorkCompRateState>\n <WorkCompLocInfo>&#xD; </WorkCompLocInfo>\n </WorkCompRateState>\n </WorkCompLineBusiness>\n <RemarkText IdRef=\"\">\n </RemarkText>\n <RemarkText IdRef=\"2323\" id=\"3434\">\n </RemarkText>\n </WorkCompPolicyQuoteInqRq>\n </InsuranceSvcRq>\n </ACORD>\n </Body>")
},

"Multiple Canonicalization with namespace definition outside of signed element": function (test) {
Expand Down
Loading