@smartsoft001-mobilems/angular 2.20.0 → 2.22.0

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.
@@ -807,8 +807,14 @@ class SeoService {
807
807
  constructor() {
808
808
  this.title = inject(Title);
809
809
  this.meta = inject(Meta);
810
+ this.platformId = inject(PLATFORM_ID);
811
+ this.isBrowser = isPlatformBrowser(this.platformId);
810
812
  }
811
813
  updateTitle(titleText) {
814
+ if (!titleText) {
815
+ console.warn('Title text is empty or undefined.');
816
+ return;
817
+ }
812
818
  const decodedTitle = this.decodeHtml(titleText);
813
819
  if (decodedTitle) {
814
820
  this.title.setTitle(decodedTitle);
@@ -818,6 +824,10 @@ class SeoService {
818
824
  metaTags.forEach((tag) => this.meta.updateTag(tag));
819
825
  }
820
826
  updateDescription(description) {
827
+ if (!description) {
828
+ console.warn('Description text is empty or undefined.');
829
+ return;
830
+ }
821
831
  const decodedDesc = this.decodeHtml(description);
822
832
  if (decodedDesc) {
823
833
  this.meta.updateTag({ name: 'description', content: decodedDesc });
@@ -848,13 +858,37 @@ class SeoService {
848
858
  decodeHtml(encodedStr) {
849
859
  if (!encodedStr)
850
860
  return encodedStr;
861
+ // Use DOMParser only in browser environments
862
+ if (this.isBrowser) {
863
+ try {
864
+ const parser = new DOMParser();
865
+ const doc = parser.parseFromString(encodedStr, 'text/html');
866
+ return doc.documentElement.textContent;
867
+ }
868
+ catch (error) {
869
+ console.warn('DOMParser decode failed, falling back to server-safe decoder', error);
870
+ }
871
+ }
872
+ // Server / SSR fallback: decode numeric entities and common named entities
851
873
  try {
852
- const parser = new DOMParser();
853
- const doc = parser.parseFromString(encodedStr, 'text/html');
854
- return doc.documentElement.textContent;
874
+ let decoded = encodedStr
875
+ .replace(/&#x([0-9A-Fa-f]+);?/g, (_m, hex) => String.fromCharCode(parseInt(hex, 16)))
876
+ .replace(/&#([0-9]+);?/g, (_m, num) => String.fromCharCode(parseInt(num, 10)));
877
+ const entities = {
878
+ amp: '&',
879
+ lt: '<',
880
+ gt: '>',
881
+ quot: '"',
882
+ apos: "'",
883
+ nbsp: '\u00A0',
884
+ };
885
+ decoded = decoded.replace(/&([a-zA-Z]+);?/g, (_m, name) => Object.prototype.hasOwnProperty.call(entities, name)
886
+ ? entities[name]
887
+ : `&${name};`);
888
+ return decoded;
855
889
  }
856
890
  catch (error) {
857
- console.warn('Failed to decode HTML', error);
891
+ console.warn('Failed to decode HTML with fallback', error);
858
892
  return encodedStr;
859
893
  }
860
894
  }