Skip to content

Commit 17f75c5

Browse files
authored
Fixes line end and white space normalization. (#196)
1 parent 40bd9e8 commit 17f75c5

File tree

3 files changed

+137
-139
lines changed

3 files changed

+137
-139
lines changed

lib/utils.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ var xml_special_to_encoded_text = {
5555

5656
function encodeSpecialCharactersInAttribute(attributeValue){
5757
return attributeValue
58-
.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
5958
.replace(/([&<"\r\n\t])/g, function(str, item){
6059
// Special character normalization. See:
6160
// - https://www.w3.org/TR/xml-c14n#ProcessingModel (Attribute Nodes)
@@ -66,7 +65,6 @@ function encodeSpecialCharactersInAttribute(attributeValue){
6665

6766
function encodeSpecialCharactersInText(text){
6867
return text
69-
.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
7068
.replace(/([&<>\r])/g, function(str, item){
7169
// Special character normalization. See:
7270
// - https://www.w3.org/TR/xml-c14n#ProcessingModel (Text Nodes)

test/c14nWithComments-unit-tests.js

Lines changed: 63 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -274,72 +274,72 @@ module.exports = {
274274

275275
"Exclusive canonicalization works on complex xml": function (test) {
276276
compare(test,
277-
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\r" +
278-
"<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\">\r" +
279-
" <Body>\r" +
280-
" <ACORD xmlns=\"http://www.ACORD.org/standards/PC_Surety/ACORD1.10.0/xml/\">\r" +
281-
" <SignonRq>\r" +
282-
" <SessKey />\r" +
283-
" <ClientDt />\r" +
284-
" <CustLangPref />\r" +
285-
" <ClientApp>\r" +
286-
" <Org p6:type=\"AssignedIdentifier\" id=\"wewe\" xmlns:p6=\"http://www.w3.org/2001/XMLSchema-instance\" />\r" +
287-
" <Name />\r" +
288-
" <Version />\r" +
289-
" </ClientApp>\r" +
290-
" <ProxyClient>\r" +
291-
" <Org p6:type=\"AssignedIdentifier\" id=\"erer\" xmlns:p6=\"http://www.w3.org/2001/XMLSchema-instance\" />\r" +
292-
" <Name>ererer</Name>\r" +
293-
" <Version>dfdf</Version>\r" +
294-
" </ProxyClient>\r" +
295-
" </SignonRq>\r" +
296-
" <InsuranceSvcRq>\r" +
297-
" <RqUID />\r" +
298-
" <SPName id=\"rter\" />\r" +
299-
" <QuickHit xmlns=\"urn:com.thehartford.bi.acord-extensions\">\r" +
300-
" <StateProvCd CodeListRef=\"dfdf\" xmlns=\"http://www.ACORD.org/standards/PC_Surety/ACORD1.10.0/xml/\" />\r" +
301-
" </QuickHit>\r" +
302-
" <WorkCompPolicyQuoteInqRq>\r" +
303-
" <RqUID>erer</RqUID>\r" +
304-
" <TransactionRequestDt id=\"erer\" />\r" +
305-
" <CurCd />\r" +
306-
" <BroadLOBCd id=\"erer\" />\r" +
307-
" <InsuredOrPrincipal>\r" +
308-
" <ItemIdInfo>\r" +
309-
" <AgencyId id=\"3434\" />\r" +
310-
" <OtherIdentifier>\r" +
311-
" <CommercialName id=\"3434\" />\r" +
312-
" <ContractTerm>\r" +
313-
" <EffectiveDt id=\"3434\" />\r" +
314-
" <StartTime id=\"3434\" />\r" +
315-
" </ContractTerm>\r" +
316-
" </OtherIdentifier>\r" +
317-
" </ItemIdInfo>\r" +
318-
" </InsuredOrPrincipal>\r" +
319-
" <InsuredOrPrincipal>\r" +
320-
" </InsuredOrPrincipal>\r" +
321-
" <CommlPolicy>\r" +
322-
" <PolicyNumber id=\"3434\" />\r" +
323-
" <LOBCd />\r" +
324-
" </CommlPolicy>\r" +
325-
" <WorkCompLineBusiness>\r" +
326-
" <LOBCd />\r" +
327-
" <WorkCompRateState>\r" +
277+
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
278+
"<Envelope xmlns=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" +
279+
" <Body>\n" +
280+
" <ACORD xmlns=\"http://www.ACORD.org/standards/PC_Surety/ACORD1.10.0/xml/\">\n" +
281+
" <SignonRq>\n" +
282+
" <SessKey />\n" +
283+
" <ClientDt />\n" +
284+
" <CustLangPref />\n" +
285+
" <ClientApp>\n" +
286+
" <Org p6:type=\"AssignedIdentifier\" id=\"wewe\" xmlns:p6=\"http://www.w3.org/2001/XMLSchema-instance\" />\n" +
287+
" <Name />\n" +
288+
" <Version />\n" +
289+
" </ClientApp>\n" +
290+
" <ProxyClient>\n" +
291+
" <Org p6:type=\"AssignedIdentifier\" id=\"erer\" xmlns:p6=\"http://www.w3.org/2001/XMLSchema-instance\" />\n" +
292+
" <Name>ererer</Name>\n" +
293+
" <Version>dfdf</Version>\n" +
294+
" </ProxyClient>\n" +
295+
" </SignonRq>\n" +
296+
" <InsuranceSvcRq>\n" +
297+
" <RqUID />\n" +
298+
" <SPName id=\"rter\" />\n" +
299+
" <QuickHit xmlns=\"urn:com.thehartford.bi.acord-extensions\">\n" +
300+
" <StateProvCd CodeListRef=\"dfdf\" xmlns=\"http://www.ACORD.org/standards/PC_Surety/ACORD1.10.0/xml/\" />\n" +
301+
" </QuickHit>\n" +
302+
" <WorkCompPolicyQuoteInqRq>\n" +
303+
" <RqUID>erer</RqUID>\n" +
304+
" <TransactionRequestDt id=\"erer\" />\n" +
305+
" <CurCd />\n" +
306+
" <BroadLOBCd id=\"erer\" />\n" +
307+
" <InsuredOrPrincipal>\n" +
308+
" <ItemIdInfo>\n" +
309+
" <AgencyId id=\"3434\" />\n" +
310+
" <OtherIdentifier>\n" +
311+
" <CommercialName id=\"3434\" />\n" +
312+
" <ContractTerm>\n" +
313+
" <EffectiveDt id=\"3434\" />\n" +
314+
" <StartTime id=\"3434\" />\n" +
315+
" </ContractTerm>\n" +
316+
" </OtherIdentifier>\n" +
317+
" </ItemIdInfo>\n" +
318+
" </InsuredOrPrincipal>\n" +
319+
" <InsuredOrPrincipal>\n" +
320+
" </InsuredOrPrincipal>\n" +
321+
" <CommlPolicy>\n" +
322+
" <PolicyNumber id=\"3434\" />\n" +
323+
" <LOBCd />\n" +
324+
" </CommlPolicy>\n" +
325+
" <WorkCompLineBusiness>\n" +
326+
" <LOBCd />\n" +
327+
" <WorkCompRateState>\n" +
328328
" <WorkCompLocInfo>\r" +
329-
" </WorkCompLocInfo>\r" +
330-
" </WorkCompRateState>\r" +
331-
" </WorkCompLineBusiness>\r" +
332-
" <RemarkText IdRef=\"\">\r" +
333-
" </RemarkText>\r" +
334-
" <RemarkText IdRef=\"2323\" id=\"3434\">\r" +
335-
" </RemarkText>\r" +
336-
" </WorkCompPolicyQuoteInqRq>\r" +
337-
" </InsuranceSvcRq>\r" +
338-
" </ACORD>\r" +
339-
" </Body>\r" +
329+
" </WorkCompLocInfo>\n" +
330+
" </WorkCompRateState>\n" +
331+
" </WorkCompLineBusiness>\n" +
332+
" <RemarkText IdRef=\"\">\n" +
333+
" </RemarkText>\n" +
334+
" <RemarkText IdRef=\"2323\" id=\"3434\">\n" +
335+
" </RemarkText>\n" +
336+
" </WorkCompPolicyQuoteInqRq>\n" +
337+
" </InsuranceSvcRq>\n" +
338+
" </ACORD>\n" +
339+
" </Body>\n" +
340340
"</Envelope>",
341341
"//*[local-name(.)='Body']",
342-
"<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>")
342+
"<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>")
343343
},
344344

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

0 commit comments

Comments
 (0)