Skip to content

Commit

Permalink
fix: handle Windows-style line endings (\r\n) correctly (#1140)
Browse files Browse the repository at this point in the history
* fix: handle Windows-style line endings (\r\n) correctly

* chore: log session
  • Loading branch information
boris-w authored Dec 6, 2024
1 parent 2b8665a commit 1f58963
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable @typescript-eslint/naming-convention */
import { Injectable } from '@nestjs/common';
import { Injectable, Logger } from '@nestjs/common';
import { Store } from 'express-session';
import { pick } from 'lodash';
import { CacheService } from '../../../cache/cache.service';
Expand All @@ -13,6 +13,7 @@ const SESSION_STORE_KEYS = ['passport', 'cookie'] as const;
export class SessionStoreService extends Store {
private readonly ttl: number;
private readonly userSessionExpire: number;
private readonly logger = new Logger(SessionStoreService.name);

constructor(
private readonly cacheService: CacheService,
Expand Down Expand Up @@ -43,15 +44,18 @@ export class SessionStoreService extends Store {
private async getCache(sid: string) {
const expire = await this.cacheService.get(`auth:session-expire:${sid}`);
if (expire) {
this.logger.log(`Session ${sid} is expired`);
return null;
}
const session = await this.cacheService.get(`auth:session-store:${sid}`);
if (!session) {
this.logger.log(`Session ${sid} not found`);
return null;
}
const userId = session.passport.user.id;
const userSessions = (await this.cacheService.get(`auth:session-user:${userId}`)) ?? {};
if (!userSessions[sid]) {
this.logger.log(`Session ${sid} not found in userSessions`);
await this.cacheService.del(`auth:session-store:${sid}`);
return null;
}
Expand All @@ -62,6 +66,7 @@ export class SessionStoreService extends Store {
delete userSessions[sid];
await this.cacheService.del(`auth:session-store:${sid}`);
await this.cacheService.set(`auth:session-user:${userId}`, userSessions, this.ttl);
this.logger.log(`Session ${sid} expired, remove from userSessions`);
return null;
}
return session;
Expand Down
5 changes: 5 additions & 0 deletions packages/core/src/utils/clipboard.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@ describe('clipboard', () => {
const data = parseClipboardText('text1\n\n"text2"');
expect(data).toEqual([['text1'], [''], ['"text2"']]);
});

it('content has windows newline', () => {
const data = parseClipboardText('text1"\r\ntext2');
expect(data).toEqual([['text1"'], ['text2']]);
});
});

describe('stringify', () => {
Expand Down
8 changes: 7 additions & 1 deletion packages/core/src/utils/clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,19 @@ export const parseClipboardText = (content: string) => {
endOfCell = true;
break;
}
} else if (content[cursor] === _newline) {
} else if (
content[cursor] === _newline ||
`${content[cursor]}${content[cursor + 1]}` === _newline
) {
if (quoted) {
cell += _newline;
} else {
endOfCell = true;
endOfRow = true;
}
if (`${content[cursor]}${content[cursor + 1]}` === _newline) {
cursor++;
}
} else {
cell += content[cursor];
}
Expand Down

0 comments on commit 1f58963

Please sign in to comment.