fix property parser
This commit is contained in:
		
							parent
							
								
									dda4e7475c
								
							
						
					
					
						commit
						befcff973a
					
				
					 2 changed files with 8 additions and 1 deletions
				
			
		| 
						 | 
				
			
			@ -30,7 +30,7 @@ const mustNumber = (v) => {
 | 
			
		|||
 | 
			
		||||
const parseSetOption = (word, types) => {
 | 
			
		||||
  let [key, value] = word.split('=');
 | 
			
		||||
  if (!value) {
 | 
			
		||||
  if (value === undefined) {
 | 
			
		||||
    value = !key.startsWith('no');
 | 
			
		||||
    key = value ? key : key.slice(2);
 | 
			
		||||
  }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,6 +9,12 @@ describe("shared/commands/parsers", () => {
 | 
			
		|||
      expect(value).to.equal('utf-8');
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it('parse set empty string', () => {
 | 
			
		||||
      let [key, value] = parsers.parseSetOption('encoding=', { encoding: 'string' });
 | 
			
		||||
      expect(key).to.equal('encoding');
 | 
			
		||||
      expect(value).to.equal('');
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
    it('parse set string', () => {
 | 
			
		||||
      let [key, value] = parsers.parseSetOption('history=50', { history: 'number' });
 | 
			
		||||
      expect(key).to.equal('history');
 | 
			
		||||
| 
						 | 
				
			
			@ -34,6 +40,7 @@ describe("shared/commands/parsers", () => {
 | 
			
		|||
    it('throws error on invalid property', () => {
 | 
			
		||||
      expect(() => parsers.parseSetOption('charset=utf-8', { charset: 'number' })).to.throw(Error, 'Not number');
 | 
			
		||||
      expect(() => parsers.parseSetOption('charset=utf-8', { charset: 'boolean' })).to.throw(Error, 'Invalid');
 | 
			
		||||
      expect(() => parsers.parseSetOption('charset=', { charset: 'boolean' })).to.throw(Error, 'Invalid');
 | 
			
		||||
      expect(() => parsers.parseSetOption('smoothscroll', { smoothscroll: 'string' })).to.throw(Error, 'Invalid');
 | 
			
		||||
      expect(() => parsers.parseSetOption('smoothscroll', { smoothscroll: 'number' })).to.throw(Error, 'Invalid');
 | 
			
		||||
    })
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Reference in a new issue