mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-28 18:26:54 +00:00
fix(client): replace apple quotes in fill in the blanks before testing (#57987)
This commit is contained in:
@@ -33,6 +33,7 @@ import Scene from '../components/scene/scene';
|
||||
import { SceneSubject } from '../components/scene/scene-subject';
|
||||
import { getChallengePaths } from '../utils/challenge-paths';
|
||||
import { isChallengeCompletedSelector } from '../redux/selectors';
|
||||
import { replaceAppleQuotes } from '../../../utils/replace-apple-quotes';
|
||||
|
||||
import './show.css';
|
||||
|
||||
@@ -133,7 +134,9 @@ const ShowFillInTheBlank = ({
|
||||
const blankAnswers = fillInTheBlank.blanks.map(b => b.answer);
|
||||
|
||||
const newAnswersCorrect = userAnswers.map(
|
||||
(userAnswer, i) => !!userAnswer && userAnswer.trim() === blankAnswers[i]
|
||||
(userAnswer, i) =>
|
||||
!!userAnswer &&
|
||||
replaceAppleQuotes(userAnswer.trim()) === blankAnswers[i]
|
||||
);
|
||||
setAnswersCorrect(newAnswersCorrect);
|
||||
const hasWrongAnswer = newAnswersCorrect.some(a => a === false);
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
import { replaceAppleQuotes } from './replace-apple-quotes';
|
||||
|
||||
describe('replaceAppleQuotes()', () => {
|
||||
it('replaces apple quotes with regular quotes', () => {
|
||||
expect(replaceAppleQuotes('“double” quotes and ‘single’ quotes')).toBe(
|
||||
`"double" quotes and 'single' quotes`
|
||||
);
|
||||
});
|
||||
|
||||
it('returns the original string if there are no smart quotes', () => {
|
||||
expect(replaceAppleQuotes('No quotes')).toBe('No quotes');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,5 @@
|
||||
export function replaceAppleQuotes(text: string): string {
|
||||
return typeof text !== 'string'
|
||||
? text
|
||||
: text.replace(/[“”]/g, '"').replace(/[‘’]/g, "'");
|
||||
}
|
||||
Reference in New Issue
Block a user