feed
feed copied to clipboard
feat(atom/rss/json): support language and on feed and feed items (#196)
Overview
This PR implements comprehensive language support across all feed formats (Atom 1.0, JSON Feed 1.1, and RSS 2.0), addressing issue #196 which requested language support in Atom feeds. The implementation goes beyond the original request to provide consistent language functionality across all supported feed formats.
What's New
Atom 1.0 Language Support
-
Feed-level language: Added
xml:langattribute to<feed>element when language is specified -
Per-item language: Individual
<entry>elements can have their ownxml:langattributes - Security: Language values are properly sanitized to prevent XML injection attacks
- Standards compliance: Follows Atom 1.0 specification for language declarations
JSON Feed 1.1 Enhancement
-
Upgraded to JSON Feed 1.1: Updated from version 1.0 to support the
languagefield -
Feed-level language: Added
languagefield to top-level feed object - Per-item language: Individual items can specify their own language
- Backward compatibility: Maintains compatibility while adding new features
RSS 2.0 Verification
-
Confirmed existing support: RSS 2.0 already had channel-level
<language>element support - Added test coverage: Comprehensive tests for RSS language functionality
- Documented limitations: RSS 2.0 spec doesn't support per-item language (by design)
Technical Implementation
Type System Updates
- Added
language?: stringto theIteminterface for per-item language support - Existing
FeedOptions.languagefield was already present and working
Security Enhancements
- Language attributes are sanitized using the existing
sanitize()function - Prevents XML/XSS injection attacks via malformed language codes
Standards Compliance
-
Atom: Uses
xml:langattributes as per W3C Atom specification - JSON Feed: Follows JSON Feed 1.1 specification for language support
- RSS: Respects RSS 2.0 limitations (channel-level only)
Testing
Created dedicated test files for maintainability:
- atom1.language.test.ts
- json.language.test.ts
- rss2.language.test.ts
Test Coverage Includes:
- Feed-level and item-level language support
- Multiple language codes (en, fr, es-ES, zh-CN, ja-JP, pt-BR, etc.)
- Security testing with malicious input
- Edge cases and validation
- Format-specific behavior verification
Language Support Matrix
| Format | Feed-Level | Item-Level | Implementation Status |
|---|---|---|---|
| Atom 1.0 | β
xml:lang |
β
xml:lang |
Complete |
| JSON Feed 1.1 | β
language |
β
language |
Complete |
| RSS 2.0 | β
<language> |
β Spec limitation | Complete |
Usage Examples
Basic Feed-Level Language
const feed = new Feed({
title: "My Blog",
language: "en-US", // Now supported across all formats
// ... other options
});
Per-Item Language Support
feed.addItem({
title: "Article en FranΓ§ais",
language: "fr-FR", // Atom & JSON Feed only
// ... other item properties
});
Related Issues
- Closes #196 (language should be supported in atom feeds)
- Enhances overall feed internationalization support