@websolutespa/bom-mixer-models 1.8.2 → 1.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @websolutespa/bom-mixer-models
2
2
 
3
+ ## 1.8.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Modified: sitemapHandler added escapeHtml
8
+
9
+ ## 1.8.3
10
+
11
+ ### Patch Changes
12
+
13
+ - Modified: sitemapHandler added encodeURI
14
+
3
15
  ## 1.8.2
4
16
 
5
17
  ### Patch Changes
package/dist/index.d.ts CHANGED
@@ -210,6 +210,7 @@ type ISiteMap = {
210
210
  updatedAt?: Date;
211
211
  };
212
212
  declare function getSiteMapIndex(origin: string): Promise<string>;
213
+ declare function escapeHtml(string: string): string;
213
214
  declare function getSiteMapXML(origin: string, marketId?: string, localeId?: string): Promise<string>;
214
215
  declare function getSiteMapXSL(localeId?: string): Promise<string>;
215
216
 
@@ -333,4 +334,4 @@ declare function resolveStructuredDataOrganization(page: IPage, brand?: IBrand):
333
334
  declare function resolveStructuredDataBrand(page: IPage, brand?: IBrand): StructuredDataBrand;
334
335
  declare function resolveStructuredData(page: IPage, types?: Partial<StructuredDataCollections>, brand?: IBrand): string | undefined;
335
336
 
336
- export { IAddress, IAddressOptions, IAppProps, IApplication, IApplicationProps, IBrand, ICompanyAddress, IFeatureType, ILazyComponent, ILazyComponentFunc, ILazyComponentProps, ILazyFuncProps, ILazyModules, ILazyProps, ILazyStaticProps, ILazyStaticPropsFunc, ILazyableProps, ILazyedProps, ILink, IModelStore, INullableLazyableProps, ISiteMap, LAZY_PROPS, NotFound, PartialPageProps, SeoWeight, StaticPath, StructuredDataAddress, StructuredDataArticle, StructuredDataBrand, StructuredDataCollections, StructuredDataEvent, StructuredDataKeys, StructuredDataOffer, StructuredDataOrganization, StructuredDataPerformingGroup, StructuredDataPerson, StructuredDataPlace, StructuredDataProduct, categoryToRouteLink, findManyPages, findOnePage, getAddressOptions, getBreadcrumbFromSegments, getCaptionsVttProps, getCategories, getCategory, getCountries, getCountry, getDecoratedComponents, getErrorPageLayout, getFeatureType, getFeatureTypes, getLabel, getLabels, getLayout, getLocale, getLocaleFromProps, getLocales, getMarket, getMarkets, getMenu, getMenus, getPage, getPageCategory, getPageProps, getPageRoutes, getPreviewProps, getProvince, getProvinces, getPublicUrl, getRedirect, getRedirects, getRegion, getRegions, getRoute, getRouteLinkTree, getRoutes, getRoutesForSchemas, getRoutesForTemplates, getSegments, getSeoWeight, getSiteMapIndex, getSiteMapIndexProps, getSiteMapXML, getSiteMapXMLProps, getSiteMapXSL, getSiteMapXSLProps, getStaticPathsForSchema, newRouteLink, redirectTo, resolveHref, resolveLabel, resolveMediaSrc, resolveRoute, resolveStructuredData, resolveStructuredDataArticle, resolveStructuredDataBrand, resolveStructuredDataOrganization, resolveStructuredDataProduct, resolveTemplate, routeInterceptor, routeRevalidateHandler, routeToRouteLink, withLazyProps };
337
+ export { IAddress, IAddressOptions, IAppProps, IApplication, IApplicationProps, IBrand, ICompanyAddress, IFeatureType, ILazyComponent, ILazyComponentFunc, ILazyComponentProps, ILazyFuncProps, ILazyModules, ILazyProps, ILazyStaticProps, ILazyStaticPropsFunc, ILazyableProps, ILazyedProps, ILink, IModelStore, INullableLazyableProps, ISiteMap, LAZY_PROPS, NotFound, PartialPageProps, SeoWeight, StaticPath, StructuredDataAddress, StructuredDataArticle, StructuredDataBrand, StructuredDataCollections, StructuredDataEvent, StructuredDataKeys, StructuredDataOffer, StructuredDataOrganization, StructuredDataPerformingGroup, StructuredDataPerson, StructuredDataPlace, StructuredDataProduct, categoryToRouteLink, escapeHtml, findManyPages, findOnePage, getAddressOptions, getBreadcrumbFromSegments, getCaptionsVttProps, getCategories, getCategory, getCountries, getCountry, getDecoratedComponents, getErrorPageLayout, getFeatureType, getFeatureTypes, getLabel, getLabels, getLayout, getLocale, getLocaleFromProps, getLocales, getMarket, getMarkets, getMenu, getMenus, getPage, getPageCategory, getPageProps, getPageRoutes, getPreviewProps, getProvince, getProvinces, getPublicUrl, getRedirect, getRedirects, getRegion, getRegions, getRoute, getRouteLinkTree, getRoutes, getRoutesForSchemas, getRoutesForTemplates, getSegments, getSeoWeight, getSiteMapIndex, getSiteMapIndexProps, getSiteMapXML, getSiteMapXMLProps, getSiteMapXSL, getSiteMapXSLProps, getStaticPathsForSchema, newRouteLink, redirectTo, resolveHref, resolveLabel, resolveMediaSrc, resolveRoute, resolveStructuredData, resolveStructuredDataArticle, resolveStructuredDataBrand, resolveStructuredDataOrganization, resolveStructuredDataProduct, resolveTemplate, routeInterceptor, routeRevalidateHandler, routeToRouteLink, withLazyProps };
package/dist/index.js CHANGED
@@ -23,6 +23,7 @@ __export(src_exports, {
23
23
  LAZY_PROPS: () => LAZY_PROPS,
24
24
  NotFound: () => NotFound,
25
25
  categoryToRouteLink: () => categoryToRouteLink,
26
+ escapeHtml: () => escapeHtml,
26
27
  findManyPages: () => findManyPages,
27
28
  findOnePage: () => findOnePage,
28
29
  getAddressOptions: () => getAddressOptions,
@@ -822,32 +823,71 @@ async function getSiteMapIndex(origin) {
822
823
  <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
823
824
  ${sitemaps.map((sitemap) => `
824
825
  <sitemap>
825
- <loc>${origin}${sitemap.id}</loc>${sitemap.updatedAt ? `
826
- <lastmod>${sitemap.updatedAt}</lastmod>` : ""}
826
+ <loc>${escapeHtml(encodeURI(`${origin}${sitemap.id}`))}</loc>${sitemap.updatedAt ? `
827
+ <lastmod>${escapeHtml(String(sitemap.updatedAt))}</lastmod>` : ""}
827
828
  </sitemap>
828
829
  `).join("")}
829
830
  </sitemapindex>`;
830
831
  }
831
832
  function getSiteMapXMLLastMod(canonical) {
832
833
  return canonical.updatedAt ? `
833
- <lastmod>${canonical.updatedAt}</lastmod>` : "";
834
+ <lastmod>${escapeHtml(String(canonical.updatedAt))}</lastmod>` : "";
834
835
  }
835
836
  function getSiteMapXMLImage(canonical) {
836
837
  return canonical.media ? `
837
838
  <image:image>
838
- <image:loc>${canonical.media.src || canonical.media.url}</image:loc>
839
+ <image:loc>${escapeHtml(encodeURI(`${canonical.media.src || canonical.media.url}`))}</image:loc>
839
840
  </image:image>` : "";
840
841
  }
841
842
  function getSiteMapXMLAlternates(origin, canonical) {
842
843
  return canonical.alternates.map((alternate) => `
843
- <xhtml:link href="${origin}${alternate.id}" hreflang="${alternate.locale}-${alternate.market}" rel="alternate" />`).join("");
844
+ <xhtml:link href="${escapeHtml(encodeURI(`${origin}${alternate.id}`))}" hreflang="${alternate.locale}-${alternate.market}" rel="alternate" />`).join("");
844
845
  }
845
846
  function getSiteMapXMLUrl(origin, canonical) {
846
847
  return `
847
848
  <url>
848
- <loc>${origin}${canonical.id}</loc>${getSiteMapXMLLastMod(canonical)}${getSiteMapXMLAlternates(origin, canonical)}${getSiteMapXMLImage(canonical)}
849
+ <loc>${escapeHtml(encodeURI(`${origin}${canonical.id}`))}</loc>${getSiteMapXMLLastMod(canonical)}${getSiteMapXMLAlternates(origin, canonical)}${getSiteMapXMLImage(canonical)}
849
850
  </url>`;
850
851
  }
852
+ function escapeHtml(string) {
853
+ const matchHtmlRegExp = /["'&<>]/;
854
+ const str = "" + string;
855
+ const match = matchHtmlRegExp.exec(str);
856
+ if (!match) {
857
+ return str;
858
+ }
859
+ let escape;
860
+ let html = "";
861
+ let index = 0;
862
+ let lastIndex = 0;
863
+ for (index = match.index; index < str.length; index++) {
864
+ switch (str.charCodeAt(index)) {
865
+ case 34:
866
+ escape = "&quot;";
867
+ break;
868
+ case 38:
869
+ escape = "&amp;";
870
+ break;
871
+ case 39:
872
+ escape = "&#39;";
873
+ break;
874
+ case 60:
875
+ escape = "&lt;";
876
+ break;
877
+ case 62:
878
+ escape = "&gt;";
879
+ break;
880
+ default:
881
+ continue;
882
+ }
883
+ if (lastIndex !== index) {
884
+ html += str.substring(lastIndex, index);
885
+ }
886
+ lastIndex = index + 1;
887
+ html += escape;
888
+ }
889
+ return lastIndex !== index ? html + str.substring(lastIndex, index) : html;
890
+ }
851
891
  function getSiteMapXMLUrls(origin, canonicalRoutes) {
852
892
  return canonicalRoutes.map((canonicalRoute) => getSiteMapXMLUrl(origin, canonicalRoute)).join("");
853
893
  }
@@ -1203,6 +1243,7 @@ function resolveStructuredData(page, types, brand) {
1203
1243
  LAZY_PROPS,
1204
1244
  NotFound,
1205
1245
  categoryToRouteLink,
1246
+ escapeHtml,
1206
1247
  findManyPages,
1207
1248
  findOnePage,
1208
1249
  getAddressOptions,
package/dist/index.mjs CHANGED
@@ -729,32 +729,71 @@ async function getSiteMapIndex(origin) {
729
729
  <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
730
730
  ${sitemaps.map((sitemap) => `
731
731
  <sitemap>
732
- <loc>${origin}${sitemap.id}</loc>${sitemap.updatedAt ? `
733
- <lastmod>${sitemap.updatedAt}</lastmod>` : ""}
732
+ <loc>${escapeHtml(encodeURI(`${origin}${sitemap.id}`))}</loc>${sitemap.updatedAt ? `
733
+ <lastmod>${escapeHtml(String(sitemap.updatedAt))}</lastmod>` : ""}
734
734
  </sitemap>
735
735
  `).join("")}
736
736
  </sitemapindex>`;
737
737
  }
738
738
  function getSiteMapXMLLastMod(canonical) {
739
739
  return canonical.updatedAt ? `
740
- <lastmod>${canonical.updatedAt}</lastmod>` : "";
740
+ <lastmod>${escapeHtml(String(canonical.updatedAt))}</lastmod>` : "";
741
741
  }
742
742
  function getSiteMapXMLImage(canonical) {
743
743
  return canonical.media ? `
744
744
  <image:image>
745
- <image:loc>${canonical.media.src || canonical.media.url}</image:loc>
745
+ <image:loc>${escapeHtml(encodeURI(`${canonical.media.src || canonical.media.url}`))}</image:loc>
746
746
  </image:image>` : "";
747
747
  }
748
748
  function getSiteMapXMLAlternates(origin, canonical) {
749
749
  return canonical.alternates.map((alternate) => `
750
- <xhtml:link href="${origin}${alternate.id}" hreflang="${alternate.locale}-${alternate.market}" rel="alternate" />`).join("");
750
+ <xhtml:link href="${escapeHtml(encodeURI(`${origin}${alternate.id}`))}" hreflang="${alternate.locale}-${alternate.market}" rel="alternate" />`).join("");
751
751
  }
752
752
  function getSiteMapXMLUrl(origin, canonical) {
753
753
  return `
754
754
  <url>
755
- <loc>${origin}${canonical.id}</loc>${getSiteMapXMLLastMod(canonical)}${getSiteMapXMLAlternates(origin, canonical)}${getSiteMapXMLImage(canonical)}
755
+ <loc>${escapeHtml(encodeURI(`${origin}${canonical.id}`))}</loc>${getSiteMapXMLLastMod(canonical)}${getSiteMapXMLAlternates(origin, canonical)}${getSiteMapXMLImage(canonical)}
756
756
  </url>`;
757
757
  }
758
+ function escapeHtml(string) {
759
+ const matchHtmlRegExp = /["'&<>]/;
760
+ const str = "" + string;
761
+ const match = matchHtmlRegExp.exec(str);
762
+ if (!match) {
763
+ return str;
764
+ }
765
+ let escape;
766
+ let html = "";
767
+ let index = 0;
768
+ let lastIndex = 0;
769
+ for (index = match.index; index < str.length; index++) {
770
+ switch (str.charCodeAt(index)) {
771
+ case 34:
772
+ escape = "&quot;";
773
+ break;
774
+ case 38:
775
+ escape = "&amp;";
776
+ break;
777
+ case 39:
778
+ escape = "&#39;";
779
+ break;
780
+ case 60:
781
+ escape = "&lt;";
782
+ break;
783
+ case 62:
784
+ escape = "&gt;";
785
+ break;
786
+ default:
787
+ continue;
788
+ }
789
+ if (lastIndex !== index) {
790
+ html += str.substring(lastIndex, index);
791
+ }
792
+ lastIndex = index + 1;
793
+ html += escape;
794
+ }
795
+ return lastIndex !== index ? html + str.substring(lastIndex, index) : html;
796
+ }
758
797
  function getSiteMapXMLUrls(origin, canonicalRoutes) {
759
798
  return canonicalRoutes.map((canonicalRoute) => getSiteMapXMLUrl(origin, canonicalRoute)).join("");
760
799
  }
@@ -1109,6 +1148,7 @@ export {
1109
1148
  LAZY_PROPS,
1110
1149
  NotFound,
1111
1150
  categoryToRouteLink,
1151
+ escapeHtml,
1112
1152
  findManyPages,
1113
1153
  findOnePage,
1114
1154
  getAddressOptions,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@websolutespa/bom-mixer-models",
3
- "version": "1.8.2",
3
+ "version": "1.8.4",
4
4
  "description": "Mixer Models module of the BOM Repository",
5
5
  "keywords": [
6
6
  "bom",
@@ -31,8 +31,8 @@ export async function getSiteMapIndex(origin: string): Promise<string> {
31
31
  <sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
32
32
  ${sitemaps.map(sitemap => `
33
33
  <sitemap>
34
- <loc>${origin}${sitemap.id}</loc>${sitemap.updatedAt ? `
35
- <lastmod>${sitemap.updatedAt}</lastmod>` : ''}
34
+ <loc>${escapeHtml(encodeURI(`${origin}${sitemap.id}`))}</loc>${sitemap.updatedAt ? `
35
+ <lastmod>${escapeHtml(String(sitemap.updatedAt))}</lastmod>` : ''}
36
36
  </sitemap>
37
37
  `).join('')}
38
38
  </sitemapindex>`;
@@ -40,28 +40,79 @@ ${sitemaps.map(sitemap => `
40
40
 
41
41
  function getSiteMapXMLLastMod(canonical: IRouteCanonical): string {
42
42
  return canonical.updatedAt ? `
43
- <lastmod>${canonical.updatedAt}</lastmod>` : '';
43
+ <lastmod>${escapeHtml(String(canonical.updatedAt))}</lastmod>` : '';
44
44
  }
45
45
 
46
46
  function getSiteMapXMLImage(canonical: IRouteCanonical): string {
47
47
  return canonical.media ? `
48
48
  <image:image>
49
- <image:loc>${canonical.media.src || canonical.media.url}</image:loc>
49
+ <image:loc>${escapeHtml(encodeURI(`${canonical.media.src || canonical.media.url}`))}</image:loc>
50
50
  </image:image>` : '';
51
51
  }
52
52
 
53
53
  function getSiteMapXMLAlternates(origin: string, canonical: IRouteCanonical): string {
54
54
  return canonical.alternates.map(alternate => `
55
- <xhtml:link href="${origin}${alternate.id}" hreflang="${alternate.locale}-${alternate.market}" rel="alternate" />`).join('');
55
+ <xhtml:link href="${escapeHtml(encodeURI(`${origin}${alternate.id}`))}" hreflang="${alternate.locale}-${alternate.market}" rel="alternate" />`).join('');
56
56
  }
57
57
 
58
58
  function getSiteMapXMLUrl(origin: string, canonical: IRouteCanonical): string {
59
59
  return `
60
60
  <url>
61
- <loc>${origin}${canonical.id}</loc>${getSiteMapXMLLastMod(canonical)}${getSiteMapXMLAlternates(origin, canonical)}${getSiteMapXMLImage(canonical)}
61
+ <loc>${escapeHtml(encodeURI(`${origin}${canonical.id}`))}</loc>${getSiteMapXMLLastMod(canonical)}${getSiteMapXMLAlternates(origin, canonical)}${getSiteMapXMLImage(canonical)}
62
62
  </url>`;
63
63
  }
64
64
 
65
+ /*
66
+ Character Escape Code
67
+ Ampersand & &amp;
68
+ Single Quote ' &apos;
69
+ Double Quote " &quot;
70
+ Greater Than > &gt;
71
+ Less Than < &lt;
72
+ */
73
+
74
+ export function escapeHtml(string: string) {
75
+ const matchHtmlRegExp = /["'&<>]/;
76
+ const str = '' + string;
77
+ const match = matchHtmlRegExp.exec(str);
78
+ if (!match) {
79
+ return str;
80
+ }
81
+ let escape: string;
82
+ let html = '';
83
+ let index = 0;
84
+ let lastIndex = 0;
85
+ for (index = match.index; index < str.length; index++) {
86
+ switch (str.charCodeAt(index)) {
87
+ case 34: // "
88
+ escape = '&quot;';
89
+ break;
90
+ case 38: // &
91
+ escape = '&amp;';
92
+ break;
93
+ case 39: // '
94
+ escape = '&#39;';
95
+ break;
96
+ case 60: // <
97
+ escape = '&lt;';
98
+ break;
99
+ case 62: // >
100
+ escape = '&gt;';
101
+ break;
102
+ default:
103
+ continue;
104
+ }
105
+ if (lastIndex !== index) {
106
+ html += str.substring(lastIndex, index);
107
+ }
108
+ lastIndex = index + 1;
109
+ html += escape;
110
+ }
111
+ return lastIndex !== index
112
+ ? html + str.substring(lastIndex, index)
113
+ : html;
114
+ }
115
+
65
116
  function getSiteMapXMLUrls(origin: string, canonicalRoutes: IRouteCanonical[]): string {
66
117
  return canonicalRoutes.map((canonicalRoute) => getSiteMapXMLUrl(origin, canonicalRoute)).join('');
67
118
  }