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: handle Windows-style line endings (\r\n) correctly #1140

Merged
merged 2 commits into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading