Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ngStyle): do not truncate URLs #938

Merged
merged 10 commits into from
Dec 18, 2018
13 changes: 13 additions & 0 deletions src/lib/extended/style/style-transforms.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
import {customMatchers, expect} from '../../utils/testing/custom-matchers';
import {
NgStyleRawList,
NgStyleKeyValue,
NgStyleMap,
buildRawList,
buildMapFromList,
buildMapFromSet,
stringToKeyValue,
} from './style-transforms';

describe('ngStyleUtils', () => {
Expand Down Expand Up @@ -74,4 +76,15 @@ describe('ngStyleUtils', () => {
});
});

it('should convert string correctly to key value with URLs', () => {
const backgroundUrl = `background-url: url(${URL})`;
const keyValue: NgStyleKeyValue = stringToKeyValue(backgroundUrl);
expect(keyValue.key).toBe('background-url');
expect(keyValue.value).toBe(`url(${URL})`);
});

});


const URL = 'https://cloud.githubusercontent.com/assets/210413/' +
'21288118/917e3faa-c440-11e6-9b08-28aff590c7ae.png';
4 changes: 2 additions & 2 deletions src/lib/extended/style/style-transforms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ export function buildMapFromSet(source: NgStyleType, sanitize?: NgStyleSanitizer

/** Convert 'key:value' -> [key, value] */
export function stringToKeyValue(it: string): NgStyleKeyValue {
let [key, val] = it.split(':');
return new NgStyleKeyValue(key, val);
const [key, ...vals] = it.split(':');
return new NgStyleKeyValue(key, vals.join(':'));
}

/** Convert [ [key,value] ] -> { key : value } */
Expand Down
17 changes: 15 additions & 2 deletions src/lib/extended/style/style.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,18 @@ describe('style directive', () => {
matchMedia.activate('xs');
expectNativeEl(fixture, {fontSize: 19}).toHaveStyle({'font-size': '19px'}, styler);
});

it('should work with URLs', () => {
createTestComponent(`
CaerusKaru marked this conversation as resolved.
Show resolved Hide resolved
<div [ngStyle]="{'background-image': 'url(' + url + ')', 'height': '300px'}">
</div>
`);
fixture.detectChanges();
const url = styler.lookupStyle(fixture.debugElement.children[0].nativeElement,
'background-image');
const isUrl = url === `url("${URL}")` || url === `url(${URL})`;
expect(isUrl).toBeTruthy();
});
});

// *****************************************************************
Expand All @@ -156,7 +168,8 @@ describe('style directive', () => {
})
class TestStyleComponent {
fontSize: number = 0;
url = URL;
CaerusKaru marked this conversation as resolved.
Show resolved Hide resolved
}



const URL = 'https://cloud.githubusercontent.com/assets/210413/' +
'21288118/917e3faa-c440-11e6-9b08-28aff590c7ae.png';