@@ -8,6 +8,7 @@ import * as et from 'elementtree';
88
99import { IProject , ResourcesPlatform } from '../../../definitions' ;
1010import { FatalException } from '../../errors' ;
11+ import { shortid } from '../../utils/uuid' ;
1112
1213const debug = Debug ( 'ionic:cli-utils:lib:integrations:cordova:config' ) ;
1314
@@ -19,9 +20,10 @@ export interface PlatformEngine {
1920
2021export class ConfigXml {
2122 protected _doc ?: et . ElementTree ;
23+ protected _sessionid ?: string ;
2224 protected saving = false ;
2325
24- constructor ( public filePath : string ) { }
26+ constructor ( readonly filePath : string ) { }
2527
2628 get doc ( ) {
2729 if ( ! this . _doc ) {
@@ -31,6 +33,14 @@ export class ConfigXml {
3133 return this . _doc ;
3234 }
3335
36+ get sessionid ( ) {
37+ if ( ! this . _sessionid ) {
38+ throw new Error ( 'No doc loaded.' ) ;
39+ }
40+
41+ return this . _sessionid ;
42+ }
43+
3444 static async load ( filePath : string ) : Promise < ConfigXml > {
3545 if ( ! filePath ) {
3646 throw new Error ( 'Must supply file path.' ) ;
@@ -51,6 +61,7 @@ export class ConfigXml {
5161
5262 try {
5363 this . _doc = et . parse ( configFileContents ) ;
64+ this . _sessionid = shortid ( ) ;
5465 } catch ( e ) {
5566 throw new Error ( `Cannot parse config.xml file: ${ e . stack ? e . stack : e } ` ) ;
5667 }
@@ -103,7 +114,7 @@ export class ConfigXml {
103114 let navElement = root . find ( `allow-navigation[@href='${ newSrc } ']` ) ;
104115
105116 if ( ! navElement ) {
106- navElement = et . SubElement ( root , 'allow-navigation' , { href : newSrc } ) ;
117+ navElement = et . SubElement ( root , 'allow-navigation' , { sessionid : this . sessionid , href : newSrc } ) ;
107118 }
108119 }
109120
@@ -124,6 +135,12 @@ export class ConfigXml {
124135 contentElement . set ( 'src' , originalSrc ) ;
125136 delete contentElement . attrib [ 'original-src' ] ;
126137 }
138+
139+ const navElements = root . findall ( `allow-navigation[@sessionid='${ this . sessionid } ']` ) ;
140+
141+ for ( const navElement of navElements ) {
142+ root . remove ( navElement ) ;
143+ }
127144 }
128145
129146 getPreference ( prefName : string ) : string | undefined {
0 commit comments