Skip to content

Commit 2cbf065

Browse files
committed
feature complete, now only bugfices and security enhancements
1 parent 9490c8e commit 2cbf065

16 files changed

+2573
-2580
lines changed

.vscode/settings.json

Lines changed: 0 additions & 7 deletions
This file was deleted.

Makefile

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,17 @@
11
# Makefile for bash-ini-parser
22

3-
.PHONY: web clean lint test
4-
5-
# Build the web demo
6-
web:
7-
@echo "Building web demo..."
8-
@chmod +x build_web_demo.sh
9-
@./build_web_demo.sh --output index.html
10-
@echo "Generated index.html"
3+
.PHONY: clean lint test tests
114

125
# Clean generated files
136
clean:
147
@echo "Cleaning generated files..."
15-
@rm -f index.html
168
@echo "Clean complete."
179

1810
# Lint shell scripts with shellcheck
1911
lint:
2012
@echo "Running shellcheck..."
21-
@shellcheck lib_ini.sh
22-
@shellcheck build_web_demo.sh
23-
@shellcheck run_tests.sh
13+
@chmod +x lint.sh
14+
@./lint.sh || true
2415
@echo "Lint complete."
2516

2617
# Run all tests
@@ -30,10 +21,13 @@ test:
3021
@./run_tests.sh
3122
@echo "Tests complete."
3223

24+
# Alias for test
25+
tests: test
26+
3327
help:
3428
@echo "Available targets:"
35-
@echo " web - Build the interactive web demo (index.html)"
3629
@echo " clean - Remove generated files"
3730
@echo " lint - Check shell scripts with shellcheck"
3831
@echo " test - Run all tests"
32+
@echo " tests - Alias for test (run all tests)"
3933
@echo " help - Show this help message"

README.md

Lines changed: 131 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,24 @@
88

99
A robust shell script library for parsing and manipulating INI configuration files in Bash.
1010

11-
## Try It Online
12-
13-
You can try the Bash INI Parser directly in your browser through our interactive web demo. The demo provides a terminal environment with pre-loaded example files so you can test the library without installation.
14-
15-
**[Try Bash INI Parser Online](https://lsferreira42.github.io/bash-ini-parser/)**
16-
1711
## Features
1812

1913
- **Read and write** values from/to INI files
2014
- **List sections and keys** in INI files
2115
- **Add, update, and remove** sections and keys
16+
- **Rename sections and keys** with validation
17+
- **Validate INI file structure** for correctness
18+
- **Format and organize** INI files with indentation and sorting
19+
- **Batch operations** for efficient bulk updates
20+
- **Merge files** with configurable conflict resolution strategies
21+
- **Export to JSON and YAML** formats
2222
- **Supports complex values** including quotes, spaces, and special characters
2323
- **Array support** for storing multiple values
2424
- **Import/export functionality** between files and environment variables
2525
- **Extensive error handling** with detailed error messages
2626
- **Debug mode** for troubleshooting
2727
- **Configurable behavior** through environment variables
28+
- **Security features** including path validation, file locking, and atomic operations
2829
- **Backwards compatible** with previous versions
2930

3031
## Installation
@@ -120,6 +121,91 @@ if ini_key_exists "config.ini" "app" "version"; then
120121
fi
121122
```
122123

124+
### File Validation
125+
126+
```bash
127+
# Validate the structure of an INI file
128+
if ini_validate "config.ini"; then
129+
echo "File is valid"
130+
else
131+
echo "File has errors"
132+
fi
133+
```
134+
135+
### Get All Keys from a Section
136+
137+
```bash
138+
# Get all key=value pairs from a section at once
139+
ini_get_all "config.ini" "app"
140+
# Output:
141+
# name=My Application
142+
# version=1.0.0
143+
# debug=true
144+
```
145+
146+
### Rename Sections and Keys
147+
148+
```bash
149+
# Rename a section
150+
ini_rename_section "config.ini" "old_section" "new_section"
151+
152+
# Rename a key within a section
153+
ini_rename_key "config.ini" "app" "old_key" "new_key"
154+
```
155+
156+
### Format INI Files
157+
158+
```bash
159+
# Format file with indentation and sorted keys
160+
ini_format "config.ini" 2 1
161+
# Parameters: file, indent_spaces, sort_keys (0=no, 1=yes)
162+
163+
# Basic formatting (no indentation, no sorting)
164+
ini_format "config.ini"
165+
```
166+
167+
### Batch Write Operations
168+
169+
```bash
170+
# Write multiple key-value pairs at once
171+
ini_batch_write "config.ini" "app" \
172+
"name=MyApp" \
173+
"version=1.0" \
174+
"debug=true" \
175+
"timeout=30"
176+
```
177+
178+
### Merge INI Files
179+
180+
```bash
181+
# Merge source.ini into target.ini with overwrite strategy
182+
ini_merge "source.ini" "target.ini" "overwrite"
183+
184+
# Available strategies:
185+
# - "overwrite": Replace existing values with source values
186+
# - "skip": Keep existing values, only add new keys
187+
# - "merge": Append source values to existing values (comma-separated)
188+
189+
# Merge only specific sections
190+
ini_merge "source.ini" "target.ini" "overwrite" "section1" "section2"
191+
```
192+
193+
### Export to JSON and YAML
194+
195+
```bash
196+
# Export to JSON (compact format)
197+
ini_to_json "config.ini" 0
198+
199+
# Export to JSON (pretty format with indentation)
200+
ini_to_json "config.ini" 1
201+
202+
# Export to YAML (default 2-space indent)
203+
ini_to_yaml "config.ini"
204+
205+
# Export to YAML (custom indent)
206+
ini_to_yaml "config.ini" 4
207+
```
208+
123209
## Configuration Options
124210

125211
The library's behavior can be customized by setting these variables either directly in your script after sourcing the library or as environment variables before sourcing the library:
@@ -155,9 +241,15 @@ INI_ALLOW_SPACES_IN_NAMES=1
155241
### Security Improvements
156242

157243
- **Input validation** for all parameters
244+
- **Path traversal protection** to prevent directory traversal attacks
158245
- **Secure regex handling** with proper escaping of special characters
159-
- **Temporary file security** to prevent data corruption
246+
- **Temporary file security** with automatic cleanup and tracking
160247
- **File permission checks** to ensure proper access rights
248+
- **File locking** to prevent race conditions during concurrent writes
249+
- **Atomic operations** with backup creation for data integrity
250+
- **Symlink resolution** to prevent malicious symlink attacks
251+
- **File size validation** to prevent resource exhaustion
252+
- **Environment variable name sanitization** for safe export
161253
- **Automatic directory creation** when needed
162254

163255
### Core Function Enhancements
@@ -175,10 +267,26 @@ INI_ALLOW_SPACES_IN_NAMES=1
175267
- `ini_debug` - Displays debug messages when debug mode is enabled
176268
- `ini_error` - Standardized error message format
177269
- `ini_validate_section_name` and `ini_validate_key_name` - Validate input data
270+
- `ini_validate_path` - Validates file paths and prevents traversal attacks
271+
- `ini_resolve_symlink` - Safely resolves symbolic links
272+
- `ini_check_file_size` - Validates file size limits
273+
- `ini_validate_env_var_name` - Validates environment variable names
274+
- `ini_lock_file` and `ini_unlock_file` - File locking for concurrent access
178275
- `ini_create_temp_file` - Creates temporary files securely
179276
- `ini_trim` - Removes whitespace from strings
180277
- `ini_escape_for_regex` - Properly escapes special characters
181278

279+
#### Advanced Functions
280+
- `ini_validate` - Validates complete INI file structure
281+
- `ini_get_all` - Retrieves all key-value pairs from a section
282+
- `ini_rename_section` - Renames a section in the file
283+
- `ini_rename_key` - Renames a key within a section
284+
- `ini_format` - Formats and organizes INI files
285+
- `ini_batch_write` - Writes multiple key-value pairs efficiently
286+
- `ini_merge` - Merges INI files with configurable strategies
287+
- `ini_to_json` - Exports INI file to JSON format
288+
- `ini_to_yaml` - Exports INI file to YAML format
289+
182290
### Advanced Usage Examples
183291

184292
#### Working with Multiple Files
@@ -223,6 +331,22 @@ Check the `examples` directory for complete usage examples:
223331
- `basic_usage.sh`: Demonstrates core functionality
224332
- `advanced_usage.sh`: Shows advanced features
225333

334+
## Testing
335+
336+
Run the comprehensive test suite:
337+
338+
```bash
339+
make test
340+
```
341+
342+
The test suite includes:
343+
- **Basic tests** (47 tests): Core functionality validation
344+
- **Extended tests** (24 tests): Advanced features like arrays and imports
345+
- **Environment override tests** (11 tests): Configuration option validation
346+
- **Security tests** (25 tests): Security and durability improvements
347+
- **Advanced features tests** (39 tests): New advanced features validation
348+
349+
**Total: 146 tests** covering all library functionality.
226350

227351
## License
228352

0 commit comments

Comments
 (0)