Skip to content

Commit

Permalink
Merge pull request #16726 from ckeditor/ck/16040
Browse files Browse the repository at this point in the history
Fix (ckbox): Use a safer way to convert numbers to strings to avoid issues with some bundlers. Closes #16040
  • Loading branch information
Mati365 authored Jul 15, 2024
2 parents eff837a + 3351d5f commit bd13d8f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/ckeditor5-ckbox/src/ckboxutils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,8 +225,8 @@ export default class CKBoxUtils extends Plugin {
function fetchCategories( offset: number ): Promise<{ totalCount: number; items: Array<AvailableCategory> }> {
const categoryUrl = new URL( 'categories', serviceOrigin );

categoryUrl.searchParams.set( 'limit', ITEMS_PER_REQUEST.toString() );
categoryUrl.searchParams.set( 'offset', offset.toString() );
categoryUrl.searchParams.set( 'limit', String( ITEMS_PER_REQUEST ) );
categoryUrl.searchParams.set( 'offset', String( offset ) );
categoryUrl.searchParams.set( 'workspaceId', workspaceId );

return sendHttpRequest( {
Expand Down
18 changes: 18 additions & 0 deletions packages/ckeditor5-ckbox/tests/ckboxutils.js
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,24 @@ describe( 'CKBoxUtils', () => {
sinonXHR.restore();
} );

// See: https://github.com/ckeditor/ckeditor5/issues/16040
it( 'should not use `Number#toString()` method due to minification issues on some bundlers', async () => {
const categories = createCategories( 10 );
const toStringSpy = sinon.spy( Number.prototype, 'toString' );

sinonXHR.respondWith( 'GET', CKBOX_API_URL + '/categories?limit=50&offset=0&workspaceId=workspace1', [
200,
{ 'Content-Type': 'application/json' },
JSON.stringify( {
items: categories, offset: 0, limit: 50, totalCount: 10
} )
] );

await ckboxUtils._getAvailableCategories( options );

expect( toStringSpy ).not.to.be.called;
} );

it( 'should return categories in one call', async () => {
const categories = createCategories( 10 );

Expand Down

0 comments on commit bd13d8f

Please sign in to comment.