Skip to content

Commit 6435625

Browse files
committed
fixed warnings in example code
1 parent 700a80a commit 6435625

6 files changed

Lines changed: 18 additions & 7 deletions

File tree

examples/social-demo/client/src/components/post/PostCard.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Heart, MessageCircle, Repeat2, Share, Trash2, MoreHorizontal } from 'lucide-react';
22
import { Link, useNavigate } from 'react-router-dom';
33
import { formatDistanceToNow } from 'date-fns';
4+
import { sanitizeUrl } from '../../lib/utils';
45
import Avatar from '../ui/Avatar';
56
import { useMutation, useQueryClient, useQuery } from '@tanstack/react-query';
67
import { dataApi } from '../../lib/api';
@@ -164,7 +165,7 @@ export default function PostCard({ post }) {
164165
{post.images.map((img, idx) => (
165166
<img
166167
key={idx}
167-
src={img}
168+
src={sanitizeUrl(img)}
168169
alt=""
169170
className="w-full object-cover max-h-96"
170171
onClick={(e) => e.stopPropagation()}

examples/social-demo/client/src/components/post/TweetComposer.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Image, X } from 'lucide-react';
33
import { useMutation, useQueryClient } from '@tanstack/react-query';
44
import { dataApi, storageApi } from '../../lib/api';
55
import { useAuth } from '../../contexts/AuthContext';
6+
import { sanitizeUrl } from '../../lib/utils';
67
import Avatar from '../ui/Avatar';
78
import Button from '../ui/Button';
89

@@ -106,7 +107,7 @@ export default function TweetComposer({ onSuccess }) {
106107
}`}>
107108
{previewUrls.map((url, idx) => (
108109
<div key={idx} className="relative group">
109-
<img src={url} alt="" className="w-full h-48 object-cover" />
110+
<img src={sanitizeUrl(url)} alt="" className="w-full h-48 object-cover" />
110111
<button
111112
onClick={() => removeImage(idx)}
112113
className="absolute top-2 right-2 p-1.5 bg-black/70 rounded-full hover:bg-black/90 transition-colors"

examples/social-demo/client/src/components/ui/Avatar.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { cn } from '../../lib/utils';
1+
import { cn, sanitizeUrl } from '../../lib/utils';
22

33
export default function Avatar({ src, alt, size = 'md', className, verified = false }) {
44
const sizes = {
@@ -12,7 +12,7 @@ export default function Avatar({ src, alt, size = 'md', className, verified = fa
1212
<div className="relative inline-block">
1313
<div className={cn('rounded-full overflow-hidden bg-gray-200 dark:bg-gray-800', sizes[size], className)}>
1414
{src ? (
15-
<img src={src} alt={alt} className="w-full h-full object-cover" />
15+
<img src={sanitizeUrl(src)} alt={alt} className="w-full h-full object-cover" />
1616
) : (
1717
<div className="w-full h-full flex items-center justify-center text-gray-500 dark:text-gray-400 font-bold">
1818
{alt?.charAt(0)?.toUpperCase() || '?'}

examples/social-demo/client/src/lib/utils.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,12 @@ import { twMerge } from "tailwind-merge";
44
export function cn(...inputs) {
55
return twMerge(clsx(inputs));
66
}
7+
8+
export function sanitizeUrl(url) {
9+
if (!url) return '';
10+
const sanitized = url.toString().trim();
11+
if (sanitized.toLowerCase().startsWith('javascript:')) {
12+
return 'about:blank';
13+
}
14+
return sanitized;
15+
}

examples/social-demo/client/src/pages/Profile.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import Button from '../components/ui/Button';
77
import PostCard from '../components/post/PostCard';
88
import { Calendar, Link as LinkIcon, MapPin } from 'lucide-react';
99
import { formatDistanceToNow } from 'date-fns';
10+
import { sanitizeUrl } from '../lib/utils';
1011

1112
export default function Profile() {
1213
const { username } = useParams();
@@ -95,7 +96,7 @@ export default function Profile() {
9596
{/* Banner */}
9697
<div className="h-48 bg-gradient-to-r from-primary to-blue-600">
9798
{profile.banner && (
98-
<img src={profile.banner} alt="" className="w-full h-full object-cover" />
99+
<img src={sanitizeUrl(profile.banner)} alt="" className="w-full h-full object-cover" />
99100
)}
100101
</div>
101102

packages/common/src/utils/validateData.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ function validateData(incomingData, schemaRules) {
6868
const error = validateField(value, field);
6969
if (error) return { error };
7070

71-
// Ensure defined fields are present if required (handled by validateField)
72-
// cleanData already has it, but we can be explicit
71+
7372
if (value !== undefined) {
7473
cleanData[field.key] = value;
7574
}

0 commit comments

Comments
 (0)