Skip to content

Commit

Permalink
fix(pipes): handle undefined value in slice
Browse files Browse the repository at this point in the history
Closes #7152
  • Loading branch information
cexbrayat authored and mhevery committed May 25, 2016
1 parent 1513e20 commit 83c19a1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion modules/@angular/common/src/pipes/slice_pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception';
* When operating on a [List], the returned list is always a copy even when all
* the elements are being returned.
*
* When operating on a blank value, returns it.
*
* ## List Example
*
* This `ngFor` example:
Expand All @@ -62,10 +64,10 @@ import {InvalidPipeArgumentException} from './invalid_pipe_argument_exception';
@Injectable()
export class SlicePipe implements PipeTransform {
transform(value: any, start: number, end: number = null): any {
if (isBlank(value)) return value;
if (!this.supports(value)) {
throw new InvalidPipeArgumentException(SlicePipe, value);
}
if (isBlank(value)) return value;
if (isString(value)) {
return StringWrapper.slice(value, start, end);
}
Expand Down
3 changes: 3 additions & 0 deletions modules/@angular/common/test/pipes/slice_pipe_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@ export function main() {

describe("transform", () => {

it('should return null if the value is null',
() => { expect(pipe.transform(null, [4, 2])).toBe(null); });

it('should return all items after START index when START is positive and END is omitted',
() => {
expect(pipe.transform(list, 3)).toEqual([4, 5]);
Expand Down

0 comments on commit 83c19a1

Please sign in to comment.