Skip to content

Commit 95df17a

Browse files
committed
Breaking: Coerce total and total pages link header values to integer
While this may not be the cause of #332, coercing the values to numbers will avoid any issues with leading or trailing spaces/returns, and can make it easier to utilize the returned values.
1 parent 4bf3a31 commit 95df17a

File tree

7 files changed

+12
-12
lines changed

7 files changed

+12
-12
lines changed

lib/http-transport.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ function createPaginationObject( result, options, httpTransport ) {
125125
return _paging;
126126
}
127127

128-
const totalPages = result.headers[ 'x-wp-totalpages' ];
128+
const totalPages = +result.headers[ 'x-wp-totalpages' ];
129129

130130
if ( ! totalPages || totalPages === '0' ) {
131131
// No paging: return as-is
@@ -139,7 +139,7 @@ function createPaginationObject( result, options, httpTransport ) {
139139

140140
// Store pagination data from response headers on the response collection
141141
_paging = {
142-
total: result.headers[ 'x-wp-total' ],
142+
total: +result.headers[ 'x-wp-total' ],
143143
totalPages: totalPages,
144144
links: links,
145145
};

tests/integration/categories.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ describe( 'integration: categories()', () => {
9797
.get()
9898
.then( ( categories ) => {
9999
expect( categories._paging ).toHaveProperty( 'total' );
100-
expect( categories._paging.total ).toBe( '65' );
100+
expect( categories._paging.total ).toBe( 65 );
101101
return SUCCESS;
102102
} );
103103
return expect( prom ).resolves.toBe( SUCCESS );
@@ -108,7 +108,7 @@ describe( 'integration: categories()', () => {
108108
.get()
109109
.then( ( categories ) => {
110110
expect( categories._paging ).toHaveProperty( 'totalPages' );
111-
expect( categories._paging.totalPages ).toBe( '7' );
111+
expect( categories._paging.totalPages ).toBe( 7 );
112112
return SUCCESS;
113113
} );
114114
return expect( prom ).resolves.toBe( SUCCESS );

tests/integration/comments.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ describe( 'integration: comments()', () => {
121121
.get()
122122
.then( ( posts ) => {
123123
expect( posts._paging ).toHaveProperty( 'total' );
124-
expect( posts._paging.total ).toBe( '25' );
124+
expect( posts._paging.total ).toBe( 25 );
125125
return SUCCESS;
126126
} );
127127
return expect( prom ).resolves.toBe( SUCCESS );
@@ -132,7 +132,7 @@ describe( 'integration: comments()', () => {
132132
.get()
133133
.then( ( posts ) => {
134134
expect( posts._paging ).toHaveProperty( 'totalPages' );
135-
expect( posts._paging.totalPages ).toBe( '3' );
135+
expect( posts._paging.totalPages ).toBe( 3 );
136136
return SUCCESS;
137137
} );
138138
return expect( prom ).resolves.toBe( SUCCESS );

tests/integration/media.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ describe( 'integration: media()', () => {
120120
.get()
121121
.then( ( media ) => {
122122
expect( media._paging ).toHaveProperty( 'totalPages' );
123-
expect( media._paging.totalPages ).toBe( '4' );
123+
expect( media._paging.totalPages ).toBe( 4 );
124124
return SUCCESS;
125125
} );
126126
return expect( prom ).resolves.toBe( SUCCESS );

tests/integration/pages.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ describe( 'integration: pages()', () => {
8787
.get()
8888
.then( ( pages ) => {
8989
expect( pages._paging ).toHaveProperty( 'total' );
90-
expect( pages._paging.total ).toBe( '18' );
90+
expect( pages._paging.total ).toBe( 18 );
9191
return SUCCESS;
9292
} );
9393
return expect( prom ).resolves.toBe( SUCCESS );
@@ -98,7 +98,7 @@ describe( 'integration: pages()', () => {
9898
.get()
9999
.then( ( pages ) => {
100100
expect( pages._paging ).toHaveProperty( 'totalPages' );
101-
expect( pages._paging.totalPages ).toBe( '2' );
101+
expect( pages._paging.totalPages ).toBe( 2 );
102102
return SUCCESS;
103103
} );
104104
return expect( prom ).resolves.toBe( SUCCESS );

tests/integration/posts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ describe( 'integration: posts()', () => {
140140
.get()
141141
.then( ( posts ) => {
142142
expect( posts._paging ).toHaveProperty( 'totalPages' );
143-
expect( posts._paging.totalPages ).toBe( '4' );
143+
expect( posts._paging.totalPages ).toBe( 4 );
144144
return SUCCESS;
145145
} );
146146
return expect( prom ).resolves.toBe( SUCCESS );

tests/integration/tags.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ describe( 'integration: tags()', () => {
102102
.get()
103103
.then( ( tags ) => {
104104
expect( tags._paging ).toHaveProperty( 'total' );
105-
expect( tags._paging.total ).toBe( '110' );
105+
expect( tags._paging.total ).toBe( 110 );
106106
return SUCCESS;
107107
} );
108108
return expect( prom ).resolves.toBe( SUCCESS );
@@ -113,7 +113,7 @@ describe( 'integration: tags()', () => {
113113
.get()
114114
.then( ( tags ) => {
115115
expect( tags._paging ).toHaveProperty( 'totalPages' );
116-
expect( tags._paging.totalPages ).toBe( '11' );
116+
expect( tags._paging.totalPages ).toBe( 11 );
117117
return SUCCESS;
118118
} );
119119
return expect( prom ).resolves.toBe( SUCCESS );

0 commit comments

Comments
 (0)