MOBILE-4368 core: Don't add undefined params to URL
This commit is contained in:
		
							parent
							
								
									4eb3594d9b
								
							
						
					
					
						commit
						718f95b403
					
				| @ -65,6 +65,17 @@ describe('CoreUrlUtilsProvider', () => { | ||||
|         expect(url).toEqual(originalUrl); | ||||
|     }); | ||||
| 
 | ||||
|     it('doesn\'t add undefined or null params', () => { | ||||
|         const originalUrl = 'https://moodle.org'; | ||||
|         const url = urlUtils.addParamsToUrl(originalUrl, { | ||||
|             foo: undefined, | ||||
|             bar: null, | ||||
|             baz: 1, | ||||
|         }); | ||||
| 
 | ||||
|         expect(url).toEqual('https://moodle.org?baz=1'); | ||||
|     }); | ||||
| 
 | ||||
|     it('adds anchor to URL', () => { | ||||
|         const originalUrl = 'https://moodle.org'; | ||||
|         const params = { | ||||
|  | ||||
| @ -64,18 +64,18 @@ export class CoreUrlUtilsProvider { | ||||
|         const urlAndAnchor = url.split('#'); | ||||
|         url = urlAndAnchor[0]; | ||||
| 
 | ||||
|         let separator = url.indexOf('?') != -1 ? '&' : '?'; | ||||
|         let separator = url.indexOf('?') !== -1 ? '&' : '?'; | ||||
| 
 | ||||
|         for (const key in params) { | ||||
|             let value = params[key]; | ||||
| 
 | ||||
|             if (boolToNumber && typeof value == 'boolean') { | ||||
|             if (boolToNumber && typeof value === 'boolean') { | ||||
|                 // Convert booleans to 1 or 0.
 | ||||
|                 value = value ? '1' : '0'; | ||||
|             } | ||||
| 
 | ||||
|             // Ignore objects.
 | ||||
|             if (typeof value != 'object') { | ||||
|             // Ignore objects and undefined.
 | ||||
|             if (typeof value !== 'object' && value !== undefined) { | ||||
|                 url += separator + key + '=' + value; | ||||
|                 separator = '&'; | ||||
|             } | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user